import threading import time def target(): print 'the curent threading %s is running' % threading.current_thread().name time.sleep(1) print 'the curent threading %s is ended' % threading.current_thread().name print 'the curent threading %s is running' % threading.current_thread().name t = threading.Thread(target=target) t.start() t.join() print 'the curent threading %s is ended' % threading.current_thread().name
the curent threading MainThread is running the curent threading Thread-1 is running the curent threading Thread-1 is ended the curent threading MainThread is ended
the curent threading MainThread is running the curent threading Thread-1 is running the curent threading MainThread is ended the curent threading Thread-1 is ended
import threading import time def target(): print 'the curent threading %s is running' % threading.current_thread().name time.sleep(4) print 'the curent threading %s is ended' % threading.current_thread().name print 'the curent threading %s is running' % threading.current_thread().name t = threading.Thread(target=target) t.setDaemon(True) t.start() t.join() print 'the curent threading %s is ended' % threading.current_thread().name
the curent threading MainThread is running the curent threading Thread-1 is runningthe curent threading MainThread is ended
import threading import time def target(): print 'the curent threading %s is running' % threading.current_thread().name time.sleep(4) print 'the curent threading %s is ended' % threading.current_thread().name print 'the curent threading %s is running' % threading.current_thread().name t = threading.Thread(target=target) t.setDaemon(True) t.start() t.join(1)
the curent threading MainThread is running the curent threading Thread-1 is running the curent threading MainThread is ended
the curent threading MainThread is running the curent threading Thread-1 is running the curent threading Thread-1 is ended the curent threading MainThread is ended
a = 3 lock = threading.Lock() def target(): print 'the curent threading %s is running' % threading.current_thread().name time.sleep(4) global a lock.acquire() try: a += 3 finally: lock.release() print 'the curent threading %s is ended' % threading.current_thread().name print 'yes'
local = threading.local()
def func(name):
print 'current thread:%s' % threading.currentThread().name
local.name = name
print "%s in %s" % (local.name,threading.currentThread().name)
t1 = threading.Thread(target=func,args=('haibo',))
t2 = threading.Thread(target=func,args=('lina',))
t1.start()
t2.start()
t1.join()
t2.join()
class MyThread(threading.Thread): def init(self): threading.Thread.init(self) def run(self): lock.acquire() print threading.currentThread().getName() lock.release() def build_worker(num): workers = [] for t in range(num): work = MyThread() work.start() workers.append(work) return workers def producer(): threads = build_worker(4) for w in threads: w.join() print 'Done'
import urllib2 from multiprocessing.dummy import Pool as ThreadPool urls = ['http://www.baidu.com','http://www.sina.com','http://www.qq.com'] pool = ThreadPool() results = pool.map(urllib2.urlopen,urls) print results pool.close() pool.join() print 'main ended'
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有