I am working on a project to run Python APScheduler as a Windows service, the results of which go to a text file. I can install and start the service without fail.
I tried several ways to start the scheduler inside the service with the most common and disappointing result: when the service stops, the scheduler thread continues to write to a text file. I have to restart my computer to kill the thread.
I tried the lock and background schedulers and they behave the same.
I played with moving scheduler.shutdown () to different places. I would like to put it in the service stop function and start the scheduler until the service receives a stop command, after which the service stop function will handle the closing of the scheduler.
Perhaps you can point me in the right direction? Here is the code sanitized to make sure you don't have to restart your computer.
import win32serviceutil import win32service import win32event import servicemanager import socket import time import logging import configparser import os from datetime import datetime from mysql.connector import errorcode from apscheduler.schedulers.background import BackgroundScheduler global FILEPATH global SERVICE
source share