使用mulitiprocessing 进行多进程非阻塞

来源:互联网 发布:手机监测软件流量 编辑:程序博客网 时间:2024/05/22 12:12
#!/usr/bin/env pythonfrom multiprocessing import Processimport osimport timedef sleeper(name, seconds):   print 'starting child process with id: ', os.getpid()   print 'parent process:', os.getppid()   print 'sleeping for %s ' % seconds   time.sleep(seconds)   print "Done sleeping"if __name__ == '__main__':   print "in parent process (id %s)" % os.getpid()   p = Process(target=sleeper, args=('bob', 5))   p.start()   print "in parent process after child process start"   print "parent process about to join child process"   #p.join() #此处为父进程等待子进程处理完毕后,才继续执行下面的,这里面是一个阻塞的过程!!   print "in parent process after child process join"    print "parent process exiting with id ", os.getpid()   print "The parent's parent process:", os.getppid()
原创粉丝点击