上一页 1 ··· 5 6 7 8 9
摘要: 完整代码如下: 生产者,producer 消费者: 阅读全文
posted @ 2017-12-01 12:45 专注于区块链开发 阅读(2715) 评论(0) 推荐(0) 编辑
摘要: 1 import select 2 import socket 3 import queue 4 5 server = socket.socket()#创建服务器端 6 server.bind(('localhost',9999))#绑定IP和端口 7 server.listen(1000)#参数为最大监听端口数量 8 server.setblocking(False)#设置为... 阅读全文
posted @ 2017-11-30 18:26 专注于区块链开发 阅读(453) 评论(0) 推荐(0) 编辑
摘要: 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 专注于区块链开发 阅读(730) 评论(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) 编辑
摘要: from multiprocessing import Process,Queue import os def f (qq): qq.put([42,None,'hello']) #将列表传入队列qq中 if __name__ == '__main__': q = Queue() #创建进程间通信专用Queue 如果使用线程queue则会出错。 p = Process(target=f,a... 阅读全文
posted @ 2017-11-28 17:42 专注于区块链开发 阅读(307) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9