Created
December 11, 2013 09:51
-
-
Save period331/7907753 to your computer and use it in GitHub Desktop.
python subProcess problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf8 | |
from multiprocessing import Process | |
import os | |
import time | |
import setproctitle | |
setproctitle.setproctitle('subprocess') | |
def targ(x): | |
setproctitle.setproctitle('subprocess_' + str(x)) | |
print '这是一个进程任务' + str(os.getpid()) | |
while 1: | |
time.sleep(0.5) | |
processes = {} | |
def createProc(x): | |
process = Process(target=targ, args=(x,)) | |
process.start() | |
processes[process.pid] = x | |
for x in range(2): | |
createProc(x) | |
for pid, x in processes.iteritems(): | |
pid, status = os.wait() | |
del processes[pid] | |
createProc(x) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment