Python Windows Service - traceback.print_exception() failed
Asked Answered
P

1

7

I've been playing around with trying to setup Python scripts (Both .PY and .EXE via Pyinstaller) as Windows Services. My challenge has been that most problems encountered don't seem to relate to my own.

I managed to successfully setup a Virtual Environment once, and get an example service running. However, in documenting my steps, and attempting to recreate the Virtual Environment and running the service I encounter issues.

> python -m venv venv
> venv\scripts\activate.bat
> pip install pypiwin32

Then as instructed in this StackOverflow Question. I followed lindsay.stevens.au's answer with running:

> python myvenv\Scripts\pywin32_postinstall.py -install

Then copying venv\Lib\site-packages\win32\pythonservice.exe to venv\Scripts\pythonservice.exe

I've been using this Service Example from HaroldMils on GitHub as app.py.

When I run this:

> python app.py install
Installing service PythonExample
Service installed

> python app.py debug
Debugging service PythonExample - press Ctrl+C to stop.
Error 0xC0000005 - Python could find the service class in the module

<Error getting traceback - traceback.print_exception() failed

(null): (null)

My previous virtual environment still works, with the exact same script. I've tried removing the virtual environment and trying again, same result. What am I doing wrong? I can't get any more debug info out of this.

On the Virtual Environment that works, I tried uninstalling pypiwin32, reinstalling, it still works.

EDIT: Using Python 3.7.1 32-Bit

Paratrooper answered 26/2, 2020 at 14:2 Comment(3)
Did you ever find a solution? I am encountering the same issue with Python 3.7.4, pywin32-228Villeneuve
No unfortunately, I gave up on the windows service method and creating a taskbar app that the user has control over. I narrowed it down to the Windows Service not running as the User but as the System. So the relative path to the Virtual Environment and where the site packages were was missing. Hard-coding the path didn't seem to help. I did manage to get a basic service running with no additional components. If you have the capability to build something without any third-party modules you should be fine. Best of Luck! -- Edit: By basic service I mean no VENV.Paratrooper
Thanks. I like the idea of a taskbar app for my application; I hadn't thought of that. I had just stumbled upon the "run as user" issue myself, but hadn't had the chance to test a solution.Villeneuve
O
0

If you are experimenting with multiple installs reinstalls, do delete pythonservice.exe from python root folder. It does not gets replaced when installing the service.

I did beat my head around it and deleting pythonservice.exe fixed it when it got copied again.

Using servicemanager==1.8.3 and pywin32==228 works for me with python 3.7

Opium answered 5/2 at 16:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.