1

I want to run python script as a service. I converted My python script to .exe application using pyinstaller and added that application to the service using sc create "service_name" binPath= "path of the script" but when i am trying to start that service using services.msc then I am getting an error

Error 1053: The service did not respond to the start or control request in a timely fashion

Python Code:

import MySQLdb

db = MySQLdb.connect("host", "user", "pass", "database")

cursor = db.cursor()

cursor.execute("Insert into table(ID,date) Values({},now())".format(10))

db.commit()

cursor.close()

db.close()

can anyone tell me why i am getting this error and how to solve it ?

Note:I am using Windows 7

python_fan
  • 113
  • 2
  • 15
  • 1
    You get the error because you have no service control code in your program. See https://stackoverflow.com/questions/32404/how-do-you-run-a-python-script-as-a-service-in-windows?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – cdarke Jun 01 '18 at 06:55
  • ok thanks.I have run this script in linux(centos 6) as a service and i was not having any problem. @cdarke – python_fan Jun 01 '18 at 06:58
  • Services (daemons) on Linux are very easy compared to services on Windows. On Windows the Service Control Manager communicates to service threads (using a named pipe) and the service has to respond within a certain time (which you can influence). Certainly a lot more work than on Linux. – cdarke Jun 01 '18 at 07:02
  • I tried that link but getting the same error Error 1053: The service did not respond to the start or control request in a timely fashion @cdarke – python_fan Jun 01 '18 at 07:26
  • If you look for "python how to write a windows service" in your search engine you will find lots about this. Personally I always write my Windows services in C. – cdarke Jun 01 '18 at 07:33
  • ok thanks let try something else @cdarke – python_fan Jun 01 '18 at 07:35
  • This book https://doc.lagout.org/programmation/python/Python%20Programming%20on%20Win32_%20Help%20for%20Windows%20Programmers%20%5BHammond%20%26%20Robinson%202000-02-03%5D.pdf has an entire chapter on writing Windows services. Just make a bit of allowance for the fact that it was written for Python 2. I take the book down off my shelf every time I need to write a service. – BoarGules Jun 01 '18 at 08:18
  • Thanks @BoarGules – python_fan Jun 01 '18 at 08:29

0 Answers0