Semaphore Techniques

Christian Heimes lists at cheimes.de
Tue Jul 28 19:19:41 EDT 2009


John D Giotta schrieb:
> I'm looking to run a process with a limit of 3 instances, but each
> execution is over a crontab interval. I've been investigating the
> threading module and using daemons to limit active thread objects, but
> I'm not very successful at grasping the documentation.
> 
> Is it possible to do what I'm trying to do and if so anyone know of a
> useful example to get started?

Since you are talking about crontab I assume that you are on an os that
supports pthreads. You problem can easily be solved with a named
semaphore (see sem_open(3) and sem_overview(7)). Unfortunately Python
doesn't expose named semaphores. The multiprocessing library uses named
semaphores but you can't set the name yourself.

You have to write your own C wrapper or search on pypi and through
Google. If you are going to write your own semaphore I highly recommend
Cython.

Christian



More information about the Python-list mailing list