0

I am finding several problems when running a python service in Windows. This is my progress so far:

  1. I could install my python service with python main.py install.
  2. I see my python service listed on Windows Services.
  3. The first time I hit "Run" a 1053 error appeared which was solved by adding some python paths to the SystemPath environment variable.
  4. Hitting "Run" again I got this message in Event Log Viewer:
    The instance's SvcRun() method failed 
    <Error getting traceback - traceback.print_exception() failed %2: %3
    
martineau
  • 119,623
  • 25
  • 170
  • 301
Ulyses
  • 101
  • 1
  • 10
  • See my answer [here](https://stackoverflow.com/questions/65020274/facing-error-when-python-exe-service-is-started-after-nssm#comment114952659_65020274) – viilpe Dec 17 '20 at 16:28

1 Answers1

0

In the instance of SVCRun() you need an try, catch sentence

for example

try: # try main
            self.main()
        except:
            servicemanager.LogErrorMsg(traceback.format_exc()) # if error print it to event log
            os._exit(-1)#return some value other than 0 to os so that service knows to restart

Go to How to keep a windows service running for more info

Lakshya Raj
  • 1,669
  • 3
  • 10
  • 34
Freyes
  • 1