Created
November 5, 2019 19:43
-
-
Save ra0x3/b06d2b837a22811e52979b1f960c34b7 to your computer and use it in GitHub Desktop.
A task processor abstraction wrapping multiprocessing.Process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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