pip install --no-index --find-links=./ PyMySQL << 특정 위치의 모듈을 설치할 경우
pip install --no-index --find-links=./ PyMySQL==1.0.2 << 특정 버전의 모듈을 설치할 경우
pip install --no-index PyMySQL << 모듈이 위치한 폴더에서 실행할 경우
➔ 테스트 Project 파일과 함께 첨부해 놓았으나 최신 버전이 필요하시면 위 링크에서 다운로드 하시면 됩니다.
Service 등록 절차
✔️ Python 예제 프로그램
#_*_ coding: utf-8 _*_
import os
import sys
import time
import logging
from datetime import datetime, timedelta
def init():
current_directory = os.path.dirname(os.path.realpath(__file__)) # .py 파일 위치
current_log_directory = os.path.join(current_directory, "Log") # 생성할 로그 폴더
try:
if not os.path.exists(current_log_directory): # 로그 폴더 존재여부 검사
os.makedirs(current_log_directory) # 폴더 생성
except OSError:
print('----------------- Error -----------------')
return -1
# 로그파일 설정
now_date_str = datetime.now().strftime('%Y%m%d_%H%M%S') # 현재 시간을 파일명으로 사용
errorlogfilename = os.path.join(current_log_directory , "Log_%s.log" % (now_date_str)) # 로그파일의 전체 경로
# 로그파일 생성
logging.basicConfig(
filename=errorlogfilename,
level=logging.DEBUG,
format='[%(asctime)s][%(name)s][%(levelname)s] - %(message)s'
)
return 1
def main():
# 1초마다 로그파일에 현재 시간을 기록
for i in range(10):
out_message = "Now Time : %s" % (datetime.now().strftime('%Y-%m-%d_%H:%M:%S'))
logging.info("Now Time : %s" % (out_message))
print("Now Time : %s" % (out_message))
time.sleep(1)
return
if __name__ == '__main__':
if (init() >= 1):
while True:
main()
time.sleep(10) # 10초마다 main() 함수 실행
else:
print("Exit")
✔️ 관리자 권한으로 CMD를 실행하여 nssm이 보관된 폴더로 이동합니다.
✔️ nssm install [서비스명]을 입력합니다.
✔️ Path : Python 실행파일을 선택합니다. (Startup directory는 자동으로 채워집니다.)