Skip to content

Instantly share code, notes, and snippets.

@period331
Created Dec 11, 2013
Embed
What would you like to do?
python subProcess problem
# 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