上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 19 下一页
摘要: #网页爬取import urllib,time,geventimport urllib.requestfrom gevent import monkeymonkey.patch_all()#把当前程序的所有IO的操作给我单独的做上标记def f(url): print('GET: %s' % url 阅读全文
posted @ 2020-09-29 10:29 安好_世界 阅读(211) 评论(0) 推荐(0) 编辑
摘要: 手动切换Greenlet from greenlet import greenlet def test1(): print(12) gr2.switch()#第一次切换 print(34) gr2.switch()#第三次切换 def test2(): print(56) gr1.switch()# 阅读全文
posted @ 2020-09-28 13:57 安好_世界 阅读(159) 评论(0) 推荐(0) 编辑
摘要: #进程锁from multiprocessing import Process, Lock#进程锁 def f(l, i): l.acquire() print('hello world', i) l.release() if __name__ == '__main__': lock = Lock( 阅读全文
posted @ 2020-09-27 22:07 安好_世界 阅读(299) 评论(0) 推荐(0) 编辑
摘要: Manager: from multiprocessing import Process, Manager import os def f(d, l): d[1] = '1' d['2'] = 2 d[0.25] = None l.append(os.getpid()) print(l) if __ 阅读全文
posted @ 2020-09-27 09:25 安好_世界 阅读(185) 评论(0) 推荐(0) 编辑
摘要: from multiprocessing import Process, Queue def f(q): q.put([42, None, 'hello']) if __name__ == '__main__': q = Queue() p = Process(target=f, args=(q,) 阅读全文
posted @ 2020-09-23 11:25 安好_世界 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 1 import multiprocessing 2 import time,threading 3 4 def threading_run(): 5 print(threading.get_ident())#获取线程ID 6 7 def run(name): 8 time.sleep(2) 9 p 阅读全文
posted @ 2020-09-20 22:00 安好_世界 阅读(113) 评论(0) 推荐(0) 编辑
摘要: queue.Queue(maxsize=0) #先入先出,maxsize限制数量 queue.LifoQueue(maxsize=0) #last in fisrt out queue.PriorityQueue(maxsize=0) #存储数据时可设置优先级的队列 Queue.put(item,  阅读全文
posted @ 2020-09-19 18:16 安好_世界 阅读(185) 评论(0) 推荐(0) 编辑
摘要: import time,threadingevent = threading.Event()def lighter(): count =0 event.set()#先设置红绿灯,设置一个全局变量标志位 while True: if count >5 and count<10:#改成红灯 event. 阅读全文
posted @ 2020-09-19 11:45 安好_世界 阅读(650) 评论(0) 推荐(0) 编辑
摘要: import threading,timedef run(n): lock.acquire()#获取锁 global number number +=1 lock.release()#释放锁 time.sleep(1)#加在释放前会要50秒lock = threading.Lock()#实例numb 阅读全文
posted @ 2020-09-14 22:23 安好_世界 阅读(280) 评论(0) 推荐(0) 编辑
摘要: #直接调用import threading,timedef run(n): print('running ...',n) time.sleep(2)t1 = threading.Thread(target=run,args=("test1",))#生成一个线程实例t2 = threading.Thr 阅读全文
posted @ 2020-09-14 10:39 安好_世界 阅读(127) 评论(0) 推荐(0) 编辑
上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 19 下一页