Allow only one python script instance

Possible duplicate:
Python: one instance of the program

What is the best way to ensure that only one copy of a python script works? I'm having problems with zombie pythons. I'm tired of creating a write lock with open("lock","w"), but python doesn't notify me if the file already has a write lock, it just seems to be waiting.

+3
source share
2 answers

Try:

import os
os.open("lock", os.O_CREAT|os.O_EXCL)

Documentation for os.open and its flags .

+3
source

: Python?. .

( portalocker.LOCK_EX!|portalocker.LOCK_NB . , script .)

+1

Source: https://habr.com/ru/post/1754509/


All Articles