2

I have a python script that running on windows server 2008 on cmd line. I don't need any interact during script running. By the way the script is running during about a week. So if the server disconnects my connection for some reason, my script stops and I have to start over and over again. It is huge trouble for me and I don't know how to solve this problem.

Here is my question.

How to run a python script in backround on windows server even user disconnect from the server?

Thanks in advance for your help.

3 Answers3

1

You may use my own solution to do it under Windows: https://github.com/fomalhaut88/pydaemon. All you need is to create a class that runs the function from your script. The advantage of this approach is that you can add many other daemon processes and control them through pydaemon.

If it looks too heavy and complicated for you, you may wrap your script with an infinite loop in order to avoid stopping if it fails:

# yourscript.py
while True:
    try:
        ... # doing your stuff
    except:
        pass

To start it in background you may use following command:

start /MIN "" python yourscript.py
Fomalhaut
  • 8,590
  • 8
  • 51
  • 95
0

Maybe your want to hide your running window?

Write a vbs script to run your python script. Create a file named start.vbs

    Set ws = CreateObject("Wscript.Shell")
    ws.run "cmd /c python your_python_script.py",0

Then you can double click start.vbs to run your script backround.

Thomas
  • 130
  • 15
-1

try to spin up an AWS instance and run it on a more reliable server. Or you can look into hadoop to process the code across multiple fail-safe servers

Nate May
  • 3,814
  • 7
  • 33
  • 86