I'm trying to make a Windows service using python and started by using this service example. As a script it works, it gets installed, it runs when given the Start flag. But for portability reasons, I want to create an executable file from which the service can be run, so I used cx_Freeze to do so (code below - I know there are some extra packages there, but that doesn't affect the process, or at least I don't think so).
from cx_Freeze import setup, Executable
import os
import sys
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
base = None
if sys.platform == "win32":
base = "Win32GUI"
executables = [Executable(script="PythonCornerExample.py",
targetName="PythonCornerExample.exe", base=base)]
packages = ["time", "datetime", "os", "sqlite3", "win32timezone"]
options = {
'build_exe': {
'packages':packages,
'include_files': [
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll')
],
},
}
setup(
name = "PythonCornerExample",
options = options,
description = 'Bla bla',
executables = executables
)
Running the service using the new executable file now only works if I use the Debug flag and I can't figure out why. When using the Start flag it doesn't do anything, and if I try starting it from Windows Services, I get the "The service did not respond to the start or control request in a timely fashion." error.
I have added the path to the executable to PATH in System Variables, I run cmd as administrator, I have copied pythoncom36.dll from the pywin32_system32 folder to the win32 folder in python's site-packages, I gave permission to users in Registry Editor..
If there is anything you think I missed, please share!
I'm running python3.6 on a Windows7 and I'm using cx_Freeze 5.1.1.
UPDATE:
If this will give you a clue: when running the script (install/start/stop) I get some feedback like "Installing service" or "Starting service". When I run the executable I get no such feedback.