当前位置: 首页>>代码示例>>Python>>正文


Python Process.done_event方法代码示例

本文整理汇总了Python中multiprocessing.Process.done_event方法的典型用法代码示例。如果您正苦于以下问题:Python Process.done_event方法的具体用法?Python Process.done_event怎么用?Python Process.done_event使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在multiprocessing.Process的用法示例。


在下文中一共展示了Process.done_event方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parent_run

# 需要导入模块: from multiprocessing import Process [as 别名]
# 或者: from multiprocessing.Process import done_event [as 别名]
def parent_run():

    # Make sure we can connect
    conn = psycopg2.connect(conn_string)
    curs = conn.cursor()
    curs.execute(dummy_statement)
    curs.fetchall()
    curs.close()
    conn.close()

    # Spawn workers
    children = []
    result_queue = Queue()
    start_lock = Event()
    for i in xrange(0, n_workers):
        done_event = Event()
        child = Process(target=child_run, args=(i,result_queue,start_lock,done_event))
        children.append(child)
        child.done_event = done_event

    for child in children:
        child.start()

    # and start them working
    start_lock.set()

    # wait a while for children to thrash the system
    # then ask them to finish
    time.sleep(10)
    start_lock.clear()

    # Wait until all children have reported in
    sys.stderr.write("Waiting for children to complete...")
    sys.stderr.flush()
    for child in children:
        child.done_event.wait()
    sys.stderr.write(" done\n")

    # Read the results
    results = []
    for i in range(0, len(children)):
        (worker_number, num_tx) = result_queue.get(False)
        results.append(num_tx)
    total_tx = sum(results)
    mean_tx = float(total_tx) / float(len(results))

    # and wait for children to exit
    for child in children:
        child.join()


    sys.stderr.write("Done, executed %i statements with %i conns and %i workers\n" % (total_tx, n_conns, n_workers))
    sys.stderr.write("Mean tx per worker was %.2f\n" % mean_tx)
开发者ID:faulenzer,项目名称:scrapcode,代码行数:55,代码来源:pg_mp.py


注:本文中的multiprocessing.Process.done_event方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。