2006年02月17日 星期五 10:32
写了段代码,如下,运行起来还是符合我原先的预期的。把死循环放在最后生成的线程中运行,整个程序的运行还是正常的。不晓得窗口程序,最后调用的loop之类的函数,是什么个机理。 #!/usr/bin/env python import threading, time class Myprint(threading.Thread): def __init__(self,main_name): self.f_name = main_name threading.Thread.__init__(self) def run(self): time_str=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) name_str = self.getName() while 1: time.sleep(1) print 'Main:' + self.f_name + ' Client:' + name_str +' ' + time_str class Mythread(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): name_str = self.getName() for j in range(1, 5): print 'Main:' + name_str Myclient = Myprint(name_str) Myclient.start() for i in range(1, 5): Mymain = Mythread() Mymain.start() 致 礼! charles huang 2006-02-17
2006年02月17日 星期五 11:09
On 2/17/06, charles huang <hyy at fjii.com> wrote: > 写了段代码,如下,运行起来还是符合我原先的预期的。把死循环放在最后生成的线程中运行,整个程序的运行还是正常的。不晓得窗口程序,最后调用的loop之类的函数,是什么个机理。 > > #!/usr/bin/env python > import threading, time > > class Myprint(threading.Thread): > def __init__(self,main_name): > self.f_name = main_name > threading.Thread.__init__(self) > > def run(self): > time_str=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) > name_str = self.getName() > while 1: > time.sleep(1) > print 'Main:' + self.f_name + ' Client:' + name_str +' ' + time_str > > class Mythread(threading.Thread): > def __init__(self): > threading.Thread.__init__(self) > > def run(self): > name_str = self.getName() > for j in range(1, 5): > print 'Main:' + name_str > Myclient = Myprint(name_str) > Myclient.start() > > for i in range(1, 5): > Mymain = Mythread() > Mymain.start() > > > > 致 > 礼! > > > charles huang > 2006-02-17 > 窗口程序是一个事件循环处理系统。没有事件时它就循环,有事件时就分发。 -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit
Zeuux © 2025
京ICP备05028076号