python script instance awareness/communication

104 views Asked by At

I have a script which could be run 1,2... x number of times in parallel.

foo.py &
foo.py &
...

Each script has to check the existence of a piece of hardware (open all found FTDI device, read some data, close it). foo.py checks for FTDI devices once a second & then sleeps (what happens next is user chooses one to connect to).

Now obviously each instance cannot open the same FTDI device at the same time so I am in need of some form of "communication" for locking purposes.

What I have considered so far

  1. locking file (slow... but if I have to)
  2. sockets (I can use the condition that if a socket is open then a foo.py instance is querying the USB bus for ftdi devices)
  3. python's multiprocessing library & Lock (I however cannot see how this could work since no way to share the existence of x number of foo.py's running)

Anyone have any ideas?

0

There are 0 answers