According to this answer I created a smallest Windows service in Python.
Then I ran successfully:
python.exe smallest_service.py install
and
python.exe smallest_service.py start
with error message
Starting service SmallestPythonService
Error starting service: The
service did not respond to the start or control request in a timely
fashion.
My Python version is Python 3.9.6
pip freeze
pypiwin32==223
pywin32 # file:///C:/Users/me/Downloads/pywin32-301-cp39-cp39-win_amd64.whl
How can I fix it?
Here are the list of scenarios one may see -> Error starting service: The service did not respond to the start or control request in a timely fashion.
Missing DLL file: Another instance of the error occurs when you have a missing DLL file on your computer which is used by numerous other applications as well. If this DLL file is in conflict or isn’t present at all, you will experience the error message.
Corrupt/missing system files: Another instance of why this issue occurs is because there are corrupt or missing system files on your computer. If the very installation of Windows is not proper and has issues, you will experience numerous problems including the error message under discussion.
Outdated Windows: Microsoft officially recognized this error message on their official website and even released a temporary hotfix to solve the problem. However, recently they removed the hotfix and instructed users to upgrade to the latest iteration of Windows.
Solutions
The very first thing which we should try is changing the timeout settings of your services through your registry editor. Whenever a service is requested to launch, a timer is started with a predefined value. If the service doesn’t start within this time frame, the error message comes forward reporting so. Here in this solution, we will navigate to your computer’s registry and change the value. If it isn’t present, we will create a new key for it.
-> Press Windows + R, type “regedit” in the dialogue box and press Enter.
Once in the registry editor, navigate to the following file path:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
-> search for the key of ‘ServicesPipeTimeout’. If you find it already there, you can move to directly edit. However, if you don’t find the entry, select Control, right-click on any space present at the right side of the screen and select New > DWORD
-> Name the key as ‘ServicesPipeTimeout’ and set the value as 180000 (You can also right-click the value and click Modify if the option to set the value didn’t come in your case.
-> Save changes and exit. Restart your computer completely and then try launching the service. Check if the issue is resolved.
Solution 2: Getting Ownership of the Application
Another rare case that we came across was not having the ownership of the application caused the application not to execute the service properly. This makes sense as if the application doesn’t have enough elevated access, it will not be able to send/read the response to/from a service (especially if it is a system service). In this article, we will navigate to the executable of the application and then change the ownership to our username. If successful, this will solve the problem of getting the error 1053.
Bonus Tip
Making sure .NET Frameworks are in sync: If the application/service which you are trying to launch is on another Framework than that of the hosting machine, you will experience issues. Make sure that the frameworks are in sync.
If that doesn't work for you. It might be interesting to use NSSM. It is an easy piece of code that makes any py file into a windows service.
I've also found that most service creators only work with 32bit Python, so that might also be interesting to look at.
Related
I have been attempting to run my python script as a service, and have followed the advice contained in several previous forum posts. However, these have not helped me thus far. Here is what I have attempted up until now:
Used an SMWinservice class that allowed me to install my Python script as a service. This solution, however, would not launch. If I would try to start it, I would receive an error message.
I have tried using NSSM with : nssm install myService pathToInterpreter PathToScript. Note, all files etc. can be found in the local directory of the PathToScript. For what its worth, I also tried using the GUI version of NSSM. When I rebooted my computer, it showed as "Paused" in task manager. I stopped it, and then tried to run it again, and I received an error. I have tried NSSM with both python.exe and pythonw.exe.
I suspect that a possible source of error is the fact that my program uses a text file as a configuration file. This configuration file has been coded as being in my local working directory. However, I wouldn't think this would be an issue with NSSM. I know for a fact that my program will completely exit, using the exit command, if the configuration file is not found.
I was thinking of doing a batch file and starting the batch file with the script and running it like that, but I prefer a service since it can monitor the process, can restart it, or windows can notify me via email if there is an issue with my service.
For completeness, I should also mention that the program runs without issue outside of a service. For the reason that the program runs as expected, I decided to not post the code, unless someone would like to see it for whatever reason.
Some of my Python shell scripts are newly throwing security errors under Apple OSX 10.11, El Capitan. It seems the new App Transport Security doesn't like how the scripts are calling HTTP resources in plain text, rather than using HTTPS.
Fetching http://blahblah.com
Python[5553:5648168] App Transport Security has blocked a cleartext HTTP (http://)
resource load since it is insecure. Temporary exceptions can be configured
via your app's Info.plist file.
How might I go about fixing this? There is no HTTPS resource I can call, so I'm stuck with HTTP. The advice from Apple is to make an exception in the app's info.plist file, but this is a Python script invoked from a shell script, so there is no info.plist file to be edited.
Ideas? The root problem seems to be with webkit2png, which is in Python. Its non-HTTPS requests are being blocked by ATS, and there is no info.plist to modify.
I found a solution here that worked for me: https://apple.stackexchange.com/questions/210588/how-does-one-configure-a-temporary-exception-to-ats-on-el-capitan-and-fix-webkit
First make sure you have a version of webkit2png that is new enough to have the --ignore-ssl-check option. Version 0.5 does NOT have this option.
Second, you need to edit the source file and add a couple lines of code as shown here: https://github.com/bendalton/webkit2png/commit/9a96ac8977c386a84edb674ca1518e90452cee88
Finally use option as indicated in the solution linked above (copied here for convenience):
webkit2png --ignore-ssl-check [options] [http://example/]
Thanks for Arthur Hebert
At first I'm confused for the code then I figure it out
so I summarise the steps as follows for reference
import AppKit
Add the following code in your py script
AppKit.NSBundle.mainBundle().infoDictionary()['NSAppTransportSecurity'] = dict(NSAllowsArbitraryLoads = True)
Assume you are sure to use no HTTPS resource in MAC OSX higher than 10.11
The installation of webkit2png is not necessary in my case
I have a remote interpreter set up in PyCharm.
Everytime I close and reopen PyCharm, the connection seems to be broken, and the process to "reopen" the connection doesn't feel efficient to me.
Before doing the following, it is not possible to run any script.
Here is what I usually do:
File -> Settings
Project -> Project Interpreter
Click on the gear icon on the right.
Choose "More"
With my remote interpreter selected, click on "Edit"
Change "SSH Credentials" for "Deployment Configuration" (all the info is already filled)
Click "ok" multiple times to close everything up.
At that point, I can run any scripts on the remote machine.
What is the best/fastest way to do this? (any way to "save the settings"?)
Check option "Visible only for this project" of deployment configuration. This error occurs when the check mark is set.
https://www.jetbrains.com/help/pycharm/2018.3/deployment-connection-tab.html
if this checkbox is selected in an SFTP configuration, you cannot use
its SSH credentials for configuring a remote interpreter.
This was a bug in version 4.0.2 of PyCharm and was corrected in version 4.0.3.
Edit: No longer true. I tried with another computer and having the most recent version doesn't fix the problem.
i meet the same error, file->settings checking your interpreter setting,
You don't set the 'host' and 'post',or your set but the content was clear. check again, and it truly work
I got a python program running as a windows service which does in my opinion catch all exceptions. In my development environment I cannot reproduce any situation, where no exception is logged, when the program crashes. Except 2 cases: the program is killed via Task Manager or I power off the computer.
However, on the target environment (Windows 2000 with all necessary libraries and python installed), the windows service quits suddenly ca. 4 Minutes after reboots without logging any Exception or reason for the fail. The environment was definitely not powered off.
Does anybody have a suggestion how to determine what killed the python program?
EDIT: I cannot use a debugger in the target environment (as is it is productional level). Therefore I need a way to log the reason for the failure. So, I am looking for tools or methods to log additional information at runtime (or failure time) which can be used for post-mortem analysis.
You need to give more information like "Is your program multi-threaded ?" Does the code depend on the version of Python interpreter you are using, or any imported modules used not present in the target environment ?
If you have GDB for Windows, you can do "gdb -p pid" where "pid" is the pid of the python program you are running. If there is a crash, you can get the back trace.
You may want to check also the following tools from sysinternals.com (now acquired by MSFT):
http://technet.microsoft.com/en-us/sysinternals/bb795533
such as ProcDump, Process Monitor or even Process Explorer (yet less adapted than the previous ones).
You may also be able to install a lightweight debugger such as OllyDbg, or use Moonsols's tools to monitor the guest VM's process if you happen to have this in a virtualized environment.
I wrote a temperature logger Python script and entered it as a scheduled task in Windows XP. It has the following command line:
C:\Python26\pythonw.exe "C:\path\to\templogger.py"
It writes data to a file in local public folder (e.g. fully accessible by all who login locally).
So far, I was able to achieve this objective:
1. Get the task to run even before anyone logs in (i.e. at the "Press Ctrl+Alt+Del" screen)
But I'm having problems with these:
1. When I log in, log out, then log back in, the scheduled task is no longer active. I can no longer see it in the Task Manager's Processes tab. I suspect it closes when I log out.
2. I tried to set the task's "Run As..." property to DOMAIN\my-username and also tried SYSTEM, but problem #1 above still persists.
SUMMARY:
I want my program to be running as long as Windows is active. It should not matter whether anyone has logged in or out.
P.S.
I asked the same question in Super User, and I was advised to write it as a service, which I know nothing about (except starting and stopping them). I hope to reach a wider audience here at SO.
Is it possible to run a Python script as a service in Windows? If possible, how?
http://agiletesting.blogspot.com/2005/09/running-python-script-as-windows.html
Your scenario is exactly the required use case for a service, unfortunately tasks are ill suited for what you are looking to do. That said writing services in python is not a walk in the park either, to ease the pain here is a few links I have perused in the past:
http://agiletesting.blogspot.com/2005/09/running-python-script-as-windows.html
http://mail.python.org/pipermail/python-win32/2008-April/007298.html
I used the second link in particular to create a windows scripts that was then compiled to a executable service with py2exe and installed with SrvAny.