Skip to content

Instantly share code, notes, and snippets.

@ra0x3
Created November 5, 2019 19:43
Show Gist options
  • Save ra0x3/b06d2b837a22811e52979b1f960c34b7 to your computer and use it in GitHub Desktop.
Save ra0x3/b06d2b837a22811e52979b1f960c34b7 to your computer and use it in GitHub Desktop.
A task processor abstraction wrapping multiprocessing.Process
import os
import sys
from typing import *
import multiprocessing
class Process(multiprocessing.Process):
def __init__(self, id: int, task_queue: Iterable, results: Iterable):
super(Process, self).__init__()
self.id = id
self.task_queue = task_queue
self.results = results
def run(self):
while True:
t = self.task_queue.get()
self.task_queue.task_done()
if not t:
break
self.results.put(t.run())
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment