MultiProcessing异步进程池案例

admin   ·   发表于 2个月前   ·   Python


1 Reply   |  Until 2个月前 | 29 View

admin
发表于 2个月前

>>> import multiprocessing as mp
>>> q=mp.Queue(100)
>>> def putQ(s):
...   q.put(s)
...
>>> def fit(x):
...   import time
...   time.sleep(10)
...   return "haha~"
...
>>> p=mp.Pool(5)
>>> p.apply_async(fit,[1000],callback=putQ)
<multiprocessing.pool.ApplyResult object at 0x106b55160>
>>> q.empty()
True
>>> q.empty()
False
>>> q.get()
'haha~'

评论列表

  • 加载数据中...

编写评论内容
LoginCan Publish Content