[PythonCE] Is PythonCE, PocketPC support Thread
s3010096 at kmitl.ac.th
s3010096 at kmitl.ac.th
Sat Dec 20 18:34:40 EST 2003
Need help ...
I run three thread. Each thread get System time print out then sleep.
The output is wrong. I used PocketPC ipaq h2210 and PythonCE 2.3.
Is PocketPC ipaq windowCE PythonCE support real Thread?
Or my code have problem?
Thank you very much
Chakrit Hengsirihul
----------------------- out put ---------------------------
Python 2.3 (#0, Oct 13 2003, 17:16:10) [MSC v.1200 32 bit (Unknown)] on
Pocket PC
>>> import testThread
Name: T1; sleep: 1
Name: T2; sleep: 2
Name: T3; sleep: 4
Starting threads
T1|t=1|c=1 at 15:45:6 Threads started
T3|t=4|c=1 at 15:45:6 T1|t=1|c=2 at 15:45:7 T2|t=2|c=1 at 15:45:6 >>>
T3|t=4|c=2 at 15:45:11 T1|t=1|c=3 at 15:45:12 T2|t=2|c=2 at 15:45:14
T3|t=4|c=3 at 15:45:18 T1|t=1|c=4 at 15:45:19 T2|t=2|c=3 at 15:45:22
T3|t=4|c=4 at 15:45:26 T1|t=1|c=5 at 15:45:27 T2|t=2|c=4 at 15:45:29
T3|t=4|c=5 at 15:45:33 T2|t=2|c=5 at 15:45:36
>>>
------------------------- Python file
-------------------------------------------
#file main
from T import CheckEvenThread
thread1 = CheckEvenThread( threadName='T1' ,isleepTime=1 )
thread2 = CheckEvenThread( threadName='T2' ,isleepTime=2 )
thread3 = CheckEvenThread( threadName='T3' ,isleepTime=4 )
print "\nStarting threads"
thread1.start()
thread2.start()
thread3.start()
print "Threads started\n"
----------------------------------------------
# file class
import threading
import time
class CheckEvenThread( threading.Thread ):
def __init__( self, threadName='def',isleepTime=5):
threading.Thread.__init__( self, name = threadName )
if isleepTime<1:
isleepTime=1
self.sleepTime = isleepTime
self.count=0
print "Name: %s; sleep: %d" % \
( self.getName(), self.sleepTime )
def run( self ):
while self.count<5:
self.count =self.count+1
self.li = time.localtime(time.time())
print "%s|t=%s|c=%s@%s:%s:%s " % \
( self.getName(), self.sleepTime
,self.count,self.li[3],self.li[4],self.li[5])
time.sleep( self.sleepTime )
----------------------------------------------------------------
More information about the PythonCE
mailing list