Created
December 11, 2013 10:29
-
-
Save period331/7908195 to your computer and use it in GitHub Desktop.
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
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) | |
while 1: | |
pid, status = os.wait() | |
x = processes[pid] | |
del processes[pid] | |
createProc(x) | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment