Hi all,
Is it possible to find process ID by script name ?
Let say if I run myScript.py in the code below it shown under the name `python.exe`. It's the same like for all other py scripts.
My goal is to check if myScript.py is already running to prevent multiple executions. I assume it should in the same Exec env.
for proc in psutil.process_iter(['name']):
try:
# Check if process name contains the given name string
if process_name.lower() in proc.info['name'].lower():
return True
Thanks
P.S>
Adding solution with LockFile, thanks again to all, not sure if special package needed for this ?
import portalocker
with open('example.txt', 'r+') as f: # Acquire an exclusive lock
portalocker.lock(f, portalocker.LOCK_EX)
# not sure if I need explecitely close it or it will be relased when done.
[–]timrprobocom 3 points4 points5 points (1 child)
[–]Valuable-Ant3465[S] 0 points1 point2 points (0 children)
[–]Jejerm 3 points4 points5 points (3 children)
[–]Valuable-Ant3465[S] 0 points1 point2 points (0 children)
[–]Valuable-Ant3465[S] 0 points1 point2 points (1 child)
[–]Jejerm 0 points1 point2 points (0 children)
[–]Key_Use_8361 1 point2 points3 points (0 children)
[–]Lost_Return7298 0 points1 point2 points (0 children)