Skip to content

Instantly share code, notes, and snippets.

@period331
Created December 11, 2013 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save period331/7907753 to your computer and use it in GitHub Desktop.
Save period331/7907753 to your computer and use it in GitHub Desktop.
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