zoukankan      html  css  js  c++  java
  • python 进程池Pool

    #coding=utf-8
    import multiprocessing
    import os
    import time
    import random

    def m1(x):
        time.sleep(random.random()*4)
        print "pid:",os.getpid(),x*x
        return x*x

    if __name__=='__main__':
        pool=multiprocessing.Pool(multiprocessing.cpu_count())
        iList=range(8)
        print pool.map(m1,iList)

    c:Python27Scripts>python task_test.py
    pid: 19156 4
    pid: 9544 0
    pid: 9544 25
    pid: 9544 36
    pid: 13616 1
    pid: 15892 9
    pid: 19156 16
    pid: 9544 49
    [0, 1, 4, 9, 16, 25, 36, 49]

  • 相关阅读:
    移动web基础
    CSS3
    HTML5新属性
    CSS3初体验之伪元素选择器
    HTML5+CSS3day_01
    CSS补充
    CSS_day02
    CSS_day01
    HTML_day02
    HTML_day01
  • 原文地址:https://www.cnblogs.com/xiaxiaoxu/p/8757967.html
Copyright © 2011-2022 走看看