python processing_Python processing包_程序模块 – PyPI – Python中文网

  • Post author:
  • Post category:python


示例

processing.process类遵循threading.thread的api。

例如from processing import Process, Queue

def f(q):

q.put(‘hello world’)

if __name__ == ‘__main__’:

q = Queue()

p = Process(target=f, args=[q])

p.start()

print q.get()

p.join()

同步原语如锁、信号量和条件是

可用,例如>>> from processing import Condition

>>> c = Condition()

>>> print c

), 0>

>>> c.acquire()

True

>>> print c

), 0>

也可以使用管理器在共享中创建共享对象

内存或在服务器进程中,例如>>> from processing import Manager

>>> manager = Manager()

>>> l = manager.list(range(10))

>>> l.reverse()

>>> print l

[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]

>>> print repr(l)

任务可以通过各种方式卸载到工作进程池中,

例如>>> from processing import Pool

>>> def f(x): return x*x

>>> p = Pool(4)

>>> result = p.mapAsync(f, range(10))

>>> print result.get(timeout=1)

[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]