Skip to content

Instantly share code, notes, and snippets.

@period331
Created December 11, 2013 10:29
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/7908195 to your computer and use it in GitHub Desktop.
Save period331/7908195 to your computer and use it in GitHub Desktop.
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