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
  • 313,408
  • 56
  • 485
  • 544
evg
  • 467
  • 1
  • 5
  • 13
  • 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,624
  • 4
  • 23
  • 29
0

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

cdarke
  • 40,173
  • 7
  • 78
  • 79