def run_in_subprocess(proc, func, args=(), kwargs={}, interactive=False): try: pickle.dump(func, proc.stdin) pickle.dump(args, proc.stdin) pickle.dump(kwargs, proc.stdin) proc.stdin.flush() if not interactive: result = pickle.load(proc.stdout) if 'exception' in result: raise exceptions.SubprocessException(result['exception']) return result['output'] finally: # NOTE(dmitryme): in openstack/common/processutils.py it # is suggested to sleep a little between calls to multiprocessing. # That should allow it make some necessary cleanup context.sleep(0)
def run_in_subprocess(proc, func, args=None, kwargs=None, interactive=False): args = args or () kwargs = kwargs or {} try: # TODO(elmiko) these pickle usages should be reinvestigated to # determine a more secure manner to deploy remote commands. pickle.dump(func, proc.stdin) # nosec pickle.dump(args, proc.stdin) # nosec pickle.dump(kwargs, proc.stdin) # nosec proc.stdin.flush() if not interactive: result = pickle.load(proc.stdout) # nosec if 'exception' in result: raise exceptions.SubprocessException(result['exception']) return result['output'] finally: # NOTE(dmitryme): in oslo.concurrency's file processutils.py it # is suggested to sleep a little between calls to multiprocessing. # That should allow it make some necessary cleanup context.sleep(0)