How to check a python script (test.py)is running or not on windows 10

Home / Uncategorized / How to check a python script (test.py)is running or not on windows 10

Question:
I’m trying to setup a socket connection between Python and PHP. Python will function as server and PHP as client.

I have a python script (test.py) running form PHP.
`python test.py`

how to check this (test.py) is running or not each time before running that from PHP.how to stop that if this script is running.

how can I check that this script(test.py) is running or not in task manager or anywhere else? on windows10.


Answer:
This is unorthodox, but if you want to handle a basic lock in Windows CMD, you can change your execution line to:dir .lock || echo lock > .lock && python test.py && del .lock

This code will create a lock file if it does not exist, and start the python script. If the lock file already exists it does nothing.

The lock file is deleted after that the python script executed so that you can only have one python script executing at any given time.

You might want to add absolute paths towards the proper python script or the temporary lock folder.

Note that you might have a deadlock situation if the python interpreter runs on an error.
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *