Skip to content

Instantly share code, notes, and snippets.

@Harold2017
Created October 3, 2023 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Harold2017/0406531507501e49c751f6e686d77c84 to your computer and use it in GitHub Desktop.
Save Harold2017/0406531507501e49c751f6e686d77c84 to your computer and use it in GitHub Desktop.
run python script continuously in the background on windows

https://stackoverflow.com/questions/59125493/how-to-constantly-run-python-script-in-the-background-on-windows

If you want a code to run continuously in the background, you will need to change the file extension

from .py in .pyw

Before running the script you need to do the following:

From the CMD (command prompt) console, run the command: pip install pythonw

To start the program run the following command in CMD (in the folder where the file is located): pythonw YOUR-FILE.pyw

Now the process will run continuously in the background. To stop the process, you must run the command:

TASKKILL /F /IM pythonw.exe

CAREFUL!!! All commands are run from the command line in the folder where the file is located.

If you want to simply run the file with python YOUR-FILE.pyw, you can do that too, but you should always keep the console open. You can stop the execution with ctrl + C from Command Prompt (CMD)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment