26 lines
650 B
Python
26 lines
650 B
Python
import logging
|
|
import multiprocessing
|
|
|
|
|
|
logger = logging.getLogger("main")
|
|
|
|
|
|
def wrap_in_process(fn):
|
|
manager = multiprocessing.Manager()
|
|
return_queue = manager.list()
|
|
|
|
def process_fn(*args, **kwargs):
|
|
return_queue.append(fn(*args, **kwargs))
|
|
|
|
def wrapped_fn(*args, **kwargs):
|
|
logger.debug("Starting new subprocess")
|
|
process = multiprocessing.Process(target=process_fn, args=args, kwargs=kwargs)
|
|
process.start()
|
|
process.join()
|
|
try:
|
|
return return_queue.pop(0)
|
|
except IndexError:
|
|
logger.warning("No results returned by subprocess.")
|
|
|
|
return wrapped_fn
|