Skip to content

Instantly share code, notes, and snippets.

@nbari
Created May 22, 2013 11:06
Show Gist options
  • Save nbari/5626790 to your computer and use it in GitHub Desktop.
Save nbari/5626790 to your computer and use it in GitHub Desktop.
restart process
import multiprocessing
import time
def worker(num):
print 'worker:', num
if num == 255:
print 'second child'
else:
exit(255)
if __name__ == '__main__':
jobs = []
for i in range(5):
p = multiprocessing.Process(target=worker, args=(i,))
jobs.append(p)
p.start()
for j in jobs:
j.join()
print '%s.exitcode = %s' % (j.name, j.exitcode)
if j.exitcode == 255:
time.sleep(1)
print 'restart proccess'
p = multiprocessing.Process(target=worker, args=(255,))
jobs.append(p)
p.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment