1

I am looking for methods other than file locking to make sure that only one instance of a Python script is being run at the same time.

Is there a way to identify a currently running script in memory? Perhaps by setting a flag of some kind that other instances can read so they can exit?

Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561
evg
  • 497
  • 1
  • 5
  • 14
  • 2
    possible duplicate of [Python: single instance of program](http://stackoverflow.com/questions/380870/python-single-instance-of-program) – NPE Dec 20 '11 at 16:05

2 Answers2

2

If you are running on Linux, /dev/shm is a tmpfs partition on most distros. This means that any files stored there only exist in memory and are not written to disk.

zje
  • 3,824
  • 4
  • 25
  • 31
0

If you are running on Windows, use a Mutex. You can use ctypes to call the Win32 APIs: CreateMutex, WaitForSingleObject, and ReleaseMutex.

cdarke
  • 42,728
  • 8
  • 80
  • 84