03 2017 档案

摘要:1 import string 2 path = 'waldnn' 3 with open(path,'r') as text: 4 words = [raw_word.strip(string.punctuation).lower() for raw_word in text.read().split()] 5 words_index = set(words) 6 co... 阅读全文
posted @ 2017-03-10 19:23 Erick-LONG 阅读(1613) 评论(0) 推荐(0)
摘要:生产者消费者模型 消费者consumer()函数是一个生成器函数,每次执行到yield时即挂起,并返回上一次的结果给生产者。生产者producer()接收到生成器的返回,并生成一个新的值,通过send()方法发送给消费者。 阅读全文
posted @ 2017-03-05 12:25 Erick-LONG 阅读(144) 评论(0) 推荐(0)
摘要:一、low版 二、版本二 阅读全文
posted @ 2017-03-04 20:25 Erick-LONG 阅读(237) 评论(0) 推荐(0)
摘要:进程池 p = Pool(5) p.apply 每个任务是排队进行。进程.join() # 等待 p.apply_async 每一个任务都并发执行可设置回调函数,进程.无join();进程daemon=True # 不等待 阅读全文
posted @ 2017-03-04 12:57 Erick-LONG 阅读(154) 评论(0) 推荐(0)
摘要:进程池 阅读全文
posted @ 2017-03-03 08:09 Erick-LONG 阅读(246) 评论(0) 推荐(0)
摘要:1 import queue 2 import threading 3 4 q = queue.Queue(10) 5 def product(i): 6 print('put:'+ str(i)) 7 q.put(i) 8 9 def customer(i): 10 msg = q.get() 11 print(msg) 12 13 fo... 阅读全文
posted @ 2017-03-02 21:59 Erick-LONG 阅读(182) 评论(0) 推荐(0)
摘要:import threadingimport timenum = 0lock = threading.RLock()def fun(): lock.acquire() global num num+=1 time.sleep(1) print(num) lock.release()for i in 阅读全文
posted @ 2017-03-02 21:15 Erick-LONG 阅读(156) 评论(0) 推荐(0)