[Tutor] time.sleep problems

Glen Wheeler wheelege@tsn.cc
Sat, 18 Nov 2000 19:41:39 +1100


This is a multi-part message in MIME format.

------=_NextPart_000_001B_01C05197.91FA85C0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hey guys.  I was just fiddling with threads and my code kept locking up. =
 So I deicided to strip down the code.  I did so, and it still locks up. =
 I think the culprit is the time.sleep command.  The code has been =
stripped to very simple (actually it as simple before too, but it kept =
erroring on me)

Anywho, here it is.  I use a windows computer, and Python 2.0.

import thread
from time import sleep

print "Hi this is to show some thread stuff\n"

def thred(arg):
    for i in range(10):
        print arg
        print i
        sleep(0.0001)

t =3D raw_input('Hi! --> ')

if t =3D=3D 't' :
    thread.start_new_thread(thred, (1,))

Thanks,
Glen.

------=_NextPart_000_001B_01C05197.91FA85C0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>Hey guys.&nbsp; I was just fiddling with threads and my code kept =
locking=20
up.&nbsp; So I deicided to strip down the code.&nbsp; I did so, and it =
still=20
locks up.&nbsp; I think the culprit is the time.sleep command.&nbsp; The =
code=20
has been stripped to very simple (actually it as simple before too, but =
it kept=20
erroring on me)</DIV>
<DIV>&nbsp;</DIV>
<DIV>Anywho, here it is.&nbsp; I use a windows computer, and Python =
2.0.</DIV>
<DIV>&nbsp;</DIV>
<DIV>import thread<BR>from time import sleep</DIV>
<DIV>&nbsp;</DIV>
<DIV>print "Hi this is to show some thread stuff\n"</DIV>
<DIV>&nbsp;</DIV>
<DIV>def thred(arg):<BR>&nbsp;&nbsp;&nbsp; for i in=20
range(10):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
arg<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
i<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sleep(0.0001)</DIV>
<DIV><BR>t =3D raw_input('Hi! --&gt; ')</DIV>
<DIV>&nbsp;</DIV>
<DIV>if t =3D=3D 't' :<BR>&nbsp;&nbsp;&nbsp; =
thread.start_new_thread(thred,=20
(1,))</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks,</DIV>
<DIV>Glen.</DIV></BODY></HTML>

------=_NextPart_000_001B_01C05197.91FA85C0--