tf.keras.backend.clear_session()
2024년 1월 8일 월요일
2023년 12월 13일 수요일
python pdf 에 워터마크 추가
2023년 11월 29일 수요일
python tornado 업로드 파일 사이즈.
용량이 큰 파일 업로드 시
net::ERR_CONNECTION_RESET 오류 발생할 경우.
http_server = tornado.httpserver.HTTPServer(app, max_buffer_size=10485760000)
upload_form.html
<!DOCTYPE html>
<html>
<head>
<title>File Upload Form</title>
</head>
<body>
<h2>File Upload Form</h2>
<form action="/" method="post" enctype="multipart/form-data">
<label for="file">Select a file:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" value="Upload">
</form>
</body>
</html>
main.py
import os
import tornado.web
import tornado.ioloop
UPLOAD_DIR = "uploads" # Define the directory where uploaded files will be saved
class FileUploadHandler(tornado.web.RequestHandler):
def get(self):
self.render("upload_form.html") # Render the HTML form for file uploads
def post(self):
file_info = self.request.files['file'][0] # Get file information from the request
# Extract relevant file information
file_name = file_info['filename']
file_body = file_info['body']
# Save the uploaded file to the specified directory
file_path = os.path.join(UPLOAD_DIR, file_name)
with open(file_path, 'wb') as file:
file.write(file_body)
self.write(f"File '{file_name}' uploaded successfully.")
def make_app():
return tornado.web.Application([
(r"/", FileUploadHandler),
])
if __name__ == "__main__":
app = make_app()
print("Server is running on http://localhost:8888")
http_server = tornado.httpserver.HTTPServer(app, max_buffer_size=10485760000)
http_server.listen(8888)
tornado.ioloop.IOLoop.current().start()
2023년 11월 22일 수요일
Python을 Windows service로 실행하기
pywin32 설치
python -m pip install --upgrade pywin32
- 가상환경에서 설치하면 안됨.
가상 환경 외부에서는 COM 객체, 서비스 등을 설치하고자 할 때
python Script/pywin32_postinstall.py -install
[myservice.py]
import ctypes
import time
OutputDebugString = ctypes.windll.kernel32.OutputDebugStringW
class MyService(win32serviceutil.ServiceFramework):
_svc_name_ = 'MyService'
_svc_display_name_ = 'My Service'
is_running = False
def SvcStop(self):
OutputDebugString("MyService __SvcStop__")
self.is_running = False
def SvcDoRun(self):
self.is_running = True
while self.is_running:
OutputDebugString("MyService __loop__")
time.sleep(1)
if '__main__' == __name__:
win32serviceutil.HandleCommandLine(MyService)
관리자 권한으로 PowerSell 실행
python myservice.py install
python myservice.py start
python myservice.py stop
2022년 7월 26일 화요일
mssql insert image
def insert(self, file_id, file_path):
img = Image.open(file_path)
w = int(img.width / 2)
h = int(img.height / 2)
img_resize = img.resize((w, h))
img_resize.save('./temp.png')
with open('./temp.png', 'rb') as fh:
bindata = fh.read()
buf = '0x' + binascii.hexlify(bindata).decode('ascii')
query = f"INSERT INTO {self.tablename}(FILE_ID, FILE_DATA) VALUES ({file_id}, {buf})"
self.cursor.execute(query)
self.conn.commit()
2022년 5월 16일 월요일
docker mysql 설치
docker pull mysql
docker images
docker run --name mysql-container -e MYSQL_ROOT_PASSWORD=abcd -d -p 3306:3306 mysql:latest
docker ps
docker exec -it mysql-container bash
mysql -u root -p
mysql> create database tutorial;
mysql> create user [id]@'%' identified by 'abcd';
mysql> create user [id]@localhost identified by 'abcd';
mysql> grant all privileges on tutorial.* to [id]@'%';
mysql> grant all privileges on tutorial.* to [id]@localhost;
mysql> alter user thlee@'%' identified with mysql_native_password by 'abcd';
mysql> grant all privileges on tutorial.& to [id]@172.17.0.1 with grant option;
allowPublicKeyRetrival=true
select @@datadir;
docker volume
$ docker volume create my-vol
my-vol
$ docker volume ls
DRIVER VOLUME NAME
local my-vol
$ docker volume inspect my-vol
[
{
"CreatedAt": "2022-05-11T12:02:14Z",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/my-vol/_data",
"Name": "my-vol",
"Options": {},
"Scope": "local"
}
]
docker redmine 설치
docker-composer.yml version: '3.1' services: redmine: image: redmine restart: always container_na...
-
docker-composer.yml version: '3.1' services: redmine: image: redmine restart: always container_na...
-
docker pull wurstmeister/kafka docker pull wurstmeister/zookeeper docker-compose.yml 생성 version: '2' services: zookeeper: imag...
-
import logging logger = logging.getLogger('tornado.general') logger.setLevel(logging.DEBUG) formatter = logging.Formatter([%(leve...