threads and sleep?
Andreas Kostyrka
andreas at kostyrka.org
Wed Jul 13 03:36:19 EDT 2005
Am Montag, den 04.07.2005, 15:36 -0400 schrieb Jeffrey Maitland:
> Hello all,
>
Ok, first thing to consider is that time.sleep in Python does in reality
(on Debian Linux, Python2.3) a select syscall with 3 NULLs to wait the
time. (The "real" sleep POSIX call might have stupid interactions with
signals, to be specific SIGALRM) Don't have a Python source at the
moment (I'm offline at the moment) to check how it's done in Win32.
> I am in the process of writing a multithreading program and what I was
> wondering is a sleep command in an executing function will affect the
> threads below it? Here is a basic example of what I mean.
>
> def main():
> temp_var = True
> while temp_var == True:
> if
> t = threading.Thread( target = func1, args = "String") #note
> this is probably non functional (example purposes for the question
> only)
> t.start()
> temp_var = t.isAlive()
> else:
> print "This line should display a lot"
> sleep(2)
>
> def func1(s):
> print s
>
> so the question I was wondering is if the sleep will pause the t
> thread as well as the main function or is the thread independat of the
> main function sleep?
Well, your program seems to be non-functional (missing if expression?),
but as I said above, the main thread waits via select, so the child
process should be able to run in this time (assuming time.sleep releases
the GIL, but I'd file it as a bug if it doesn't).
Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
URL: <http://mail.python.org/pipermail/python-list/attachments/20050713/944ab3e3/attachment.sig>
More information about the Python-list
mailing list