Semaphore Techniques

Carl Banks pavlovevidence at gmail.com
Wed Jul 29 01:36:49 CEST 2009


On Jul 28, 3:15 pm, John D Giotta <jdgio... at gmail.com> wrote:
> 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?

It seems like you want to limit the number of processes to three; the
threading module won't help you there because it deals with threads
within a single process.

What I'd do is to simply run the system ps to see how many processes
are running (ps is pretty versatile on most systems and can find
specifically targeted processes like you program), and exit if there
are already three.

If you really are talking about multiple threads on a single server
process, then you want to use a thread pool (create three threads, and
give them tasks as necessary).  But you'll have to have a way for the
process started by crontab to communicate with the server.


Carl Banks



More information about the Python-list mailing list