#!/usr/bin/env python import time import sys import Queue from subprocess import Popen from threading import Thread as T from multiprocessing import Process as P import multiprocessing as mp class A(P): def __init__(self): P.__init__(self) self.q = mp.Queue() def b(q): C = q.get() exit_code = C.poll() print "exit code: %s" % exit_code B = T(target = b, args=[self.q]) B.start () def run(self): C = Popen(args = '/bin/false') self.q.put(C) class A_T(T): def __init__(self): T.__init__(self) proc = Popen(args = '/bin/false') time.sleep(0.01) ec = proc.poll() print 'exit code: %s' % ec class A_T(P): def __init__(self): P.__init__(self) proc = Popen(args = '/bin/false') time.sleep(0.01) ec = proc.poll() print 'exit code: %s' % ec class B_T_T(T): def __init__(self): T.__init__(self) def run(self): proc = Popen(args = '/bin/false') time.sleep(0.01) self._watch_queue = Queue.Queue() self._watch_queue.put(proc) self._watcher = T(target=self._watch) self._watcher.start () self._watcher.join () def _watch(self): proc = self._watch_queue.get() ec = proc.poll() print 'exit code: %s' % ec class B_T_P(T): def __init__(self): T.__init__(self) def run(self): proc = Popen(args = '/bin/false') time.sleep(0.01) self._watch_queue = mp.Queue() self._watch_queue.put(proc) self._watcher = P(target=self._watch) self._watcher.start () self._watcher.join () def _watch(self): proc = self._watch_queue.get() ec = proc.poll() print 'exit code: %s' % ec class B_P_T(P): def __init__(self): P.__init__(self) def run(self): proc = Popen(args = '/bin/false') time.sleep(0.01) self._watch_queue = mp.Queue() self._watch_queue.put(proc) self._watcher = T(target=self._watch) self._watcher.start () self._watcher.join () def _watch(self): proc = self._watch_queue.get() ec = proc.poll() print 'exit code: %s' % ec class B_P_P(P): def __init__(self): P.__init__(self) def run(self): proc = Popen(args = '/bin/false') time.sleep(0.01) self._watch_queue = mp.Queue() self._watch_queue.put(proc) self._watcher = P(target=self._watch) self._watcher.start () self._watcher.join () def _watch(self): proc = self._watch_queue.get() ec = proc.poll() print 'exit code: %s' % ec class C_T_T(T): def __init__(self): T.__init__(self) self.proc = None def run(self): self.proc = Popen(args = '/bin/false') time.sleep(0.01) self._watcher = T(target=self._watch) self._watcher.start () self._watcher.join () def _watch(self): ec = self.proc.poll() print 'exit code: %s' % ec class C_T_P(T): def __init__(self): T.__init__(self) self.proc = None def run(self): self.proc = Popen(args = '/bin/false') time.sleep(0.01) self._watcher = P(target=self._watch) self._watcher.start () self._watcher.join () def _watch(self): ec = self.proc.poll() print 'exit code: %s' % ec class C_P_T(P): def __init__(self): P.__init__(self) self.proc = None def run(self): self.proc = Popen(args = '/bin/false') time.sleep(0.01) self._watcher = T(target=self._watch) self._watcher.start () self._watcher.join () def _watch(self): ec = self.proc.poll() print 'exit code: %s' % ec class C_P_P(P): def __init__(self): P.__init__(self) self.proc = None def run(self): self.proc = Popen(args = '/bin/false') time.sleep(0.01) self._watcher = P(target=self._watch) self._watcher.start () self._watcher.join () def _watch(self): ec = self.proc.poll() print 'exit code: %s' % ec class D_T_T(T): def __init__(self): T.__init__(self) def run(self): proc = Popen(args = '/bin/false') time.sleep(0.01) def watch(proc): ec = proc.poll() print 'exit code: %s' % ec self._watcher = T(target=watch, args=[proc]) self._watcher.start () self._watcher.join () class D_T_P(T): def __init__(self): T.__init__(self) def run(self): proc = Popen(args = '/bin/false') time.sleep(0.01) def watch(proc): ec = proc.poll() print 'exit code: %s' % ec self._watcher = P(target=watch, args=[proc]) self._watcher.start () self._watcher.join () class D_P_T(P): def __init__(self): P.__init__(self) def run(self): proc = Popen(args = '/bin/false') time.sleep(0.01) def watch(proc): ec = proc.poll() print 'exit code: %s' % ec self._watcher = T(target=watch, args=[proc]) self._watcher.start () self._watcher.join () class D_P_P(P): def __init__(self): P.__init__(self) def run(self): proc = Popen(args = '/bin/false') time.sleep(0.01) def watch(proc): ec = proc.poll() print 'exit code: %s' % ec self._watcher = P(target=watch, args=[proc]) self._watcher.start () self._watcher.join () class E_T (T) : def __init__(self): self._watch_queue = Queue.Queue() T.__init__(self) self._watcher = T(target = self._watch) self._watcher.start () time.sleep(0.01) def run(self): proc = Popen(args = '/bin/false') self._watch_queue.put(proc) def _watch(self): proc = self._watch_queue.get() exit_code = proc.poll() print "exit code: %s" % exit_code class E_P (P) : def __init__(self): self._watch_queue = mp.Queue() P.__init__(self) self._watcher = T(target = self._watch) self._watcher.start () time.sleep(0.01) def run(self): proc = Popen(args = '/bin/false') self._watch_queue.put(proc) def _watch(self): proc = self._watch_queue.get() exit_code = proc.poll() print "exit code: %s" % exit_code print 'A ' ; x = A() ; x.start() ; x.join() print 'A_T ' ; x = A_T() ; x.start() ; x.join() print 'A_T ' ; x = A_T() ; x.start() ; x.join() print 'B_T_T ' ; x = B_T_T() ; x.start() ; x.join() print 'B_T_P ' ; x = B_T_P() ; x.start() ; x.join() print 'B_P_T ' ; x = B_P_T() ; x.start() ; x.join() print 'B_P_P ' ; x = B_P_P() ; x.start() ; x.join() print 'C_T_T ' ; x = C_T_T() ; x.start() ; x.join() print 'C_T_P ' ; x = C_T_P() ; x.start() ; x.join() print 'C_P_T ' ; x = C_P_T() ; x.start() ; x.join() print 'C_P_P ' ; x = C_P_P() ; x.start() ; x.join() print 'D_T_T ' ; x = D_T_T() ; x.start() ; x.join() print 'D_T_P ' ; x = D_T_P() ; x.start() ; x.join() print 'D_P_T ' ; x = D_P_T() ; x.start() ; x.join() print 'D_P_P ' ; x = D_P_P() ; x.start() ; x.join() print 'E_T ' ; x = E_T() ; x.start() ; x.join() print 'E_P ' ; x = E_P() ; x.start() ; x.join()