Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Python Script as a Windows background process [duplicate]

I have been trying to code a python script which reads data from a serial port. It worked well from the command line but I need it to run as a background process without any command line interface. The script has a while loop which reads the next byte of data from a serial port and simulates a key press accordingly. For the keypresses to be focused on the current window, instead of python command line, I need the script to run as a background process. I have read few answers here but nothing rang a bell for me. Please point me in the right direction.

like image 564
Vikas D Avatar asked Sep 27 '15 14:09

Vikas D


People also ask

Can you run the same Python script twice?

You can run multiple instances of a python script from a shell however from within a python program without the use of multithreading/multiprocessing the GIL limitation will impact what you are trying to do.

How do I run a Python script in the background windows?

If you want to run any Python script in Background in Windows operating System then all you are required to do is to rename the extension of your existing Python script that you want to run in background to '. pyw'.

What happens in the background when you run a Python file?

It will directly put the output in the file you have selected.


1 Answers

On Windows, you can run a Python script in the background using the pythonw.exe executable, which will run your program with no visible process or way to interact with it. You also cannot terminate it without a system monitor. More information on pythonw.exe can be found in the answers to the question: pythonw.exe or python.exe?

like image 160
Joseph Farah Avatar answered Sep 17 '22 13:09

Joseph Farah