[Tutor] best way to run several processes over and over

Alan Gauld alan.gauld at btinternet.com
Fri Dec 5 19:29:20 CET 2008


"shawn bright" <nephish at gmail.com> wrote
> I have a rather large app that uses 14 threads that all run at the 
> same time.
> each one runs somthing like this
>
> def run():
>    while 1:
>        do a bunch of stuff
>         time.sleep(60)
>
> i have the option i guess of having fewer threads, and just calling 
> an
> outside script for some of the actions, like this
>
> def run():
>    while 1:
>        do a bunch of stuff
>         time.sleep(60)
>         os.system("run_other_scripts.py")
>
> Does one have an advantage over the other?

In general threads use a lot less resource than processes so your
existing approach should be better. BUT the sleep(60)  bothers me
slightly. A one minute delay is an age in computer terms. It might
be better to see if you can build the delay outside the threading
and have each thread run just once then die. Then restart the
threads after 60 seconds at the top level.

But whether that is really any better would require you to try it and
see I suspect. Guessing the effect of these kinds of changes is
little more than speculation...

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list