[Tutor] threading not working how about fork?
Kent Johnson
kent37 at tds.net
Thu Oct 23 00:32:01 CEST 2008
On Wed, Oct 22, 2008 at 5:44 PM, Ertl, John C CIV 63134
<john.ertl at navy.mil> wrote:
> Classification: UNCLASSIFIED
> Caveat (s): FOUO
??
> Thanks for the help and I am looking into the pyprocessing but threading is
> causing too many headaches (I may have to rewrite things). Lets say I have
> something as simple as below:
>
> def takeTime(a):
> print "Started %s" % a
> time.sleep(10)
> print "Ended %s" % a
>
> for each in [1,2,3,4,5]:
> pid = os.fork()
> takeTime(each)
>
> Each time the function is called it waits 10 seconds. And if I run it as
> above it does the first and waits 10 seconds then the second and waits ten
> seconds...etc.
You are calling takeTime() from both the parent and child process, and
you are spawning additional processes from the child process as well.
Try
if os.fork():
takeTime(each)
break
Kent
More information about the Tutor
mailing list