摘要: 1 from urllib import request 2 import gevent,time 3 from gevent import monkey#该模块让当前程序所有io操作单独标记,进行异步操作。 4 5 monkey.patch_all()#对当前程序的io操作打上补丁。没有该monkey方法,异步IO无效。 6 def f(url): 7 print('... 阅读全文
posted @ 2017-11-29 19:01 专注于区块链开发 阅读(731) 评论(0) 推荐(0) 编辑
摘要: 1 import gevent 2 def func(): 3 print('running func 111')#第一步运行 4 gevent.sleep(2)#切换到下个协程 5 print('running func 111 agin')#最后一步执行。 6 def bar(): 7 print('running func 222')#第二部运... 阅读全文
posted @ 2017-11-29 17:57 专注于区块链开发 阅读(307) 评论(0) 推荐(0) 编辑
摘要: 1 from greenlet import greenlet 2 3 def test1(): 4 print(12) 5 g2.switch()#切换到协程g2执行,保存执行状态 6 print(23) 7 g2.switch()#切换到协程g2执行,保存执行状态 8 print(34) 9 def test2(): 10 ... 阅读全文
posted @ 2017-11-29 17:29 专注于区块链开发 阅读(418) 评论(0) 推荐(0) 编辑
摘要: 1 from multiprocessing import Pool,Process 2 import time,os 3 def Foo(a):#创建函数 4 time.sleep(2) 5 print('in the process:',os.getpid(),os.getppid()) 6 return a+100 7 8 def bar(arga... 阅读全文
posted @ 2017-11-29 12:12 专注于区块链开发 阅读(2711) 评论(0) 推荐(0) 编辑
摘要: 1 from multiprocessing import Process,Manager 2 import os 3 def f(d,n): 4 d[os.getpid()] = os.getppid()#对字典d添加键值对,子进程:父进程 5 n.append(os.getpid())#将子进程添加到列表里。 6 7 if __name__ == '__mai... 阅读全文
posted @ 2017-11-29 08:37 专注于区块链开发 阅读(247) 评论(0) 推荐(0) 编辑