Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
551 B
0
Indexable
Never
class MyProcess(multiprocessing.Process):
    def __init__(self, target=None, name=None, args=(), kwargs={}, env=None):
        super().__init__(target=target, name=name, args=args, kwargs=kwargs)
        if env:
            self.env = env

    def _get_env(self):
        env = os.environ.copy()
        if hasattr(self, 'env'):
            env.update(self.env)
        return env

    def start(self):
        self._set_process_env()
        super().start()

    def _set_process_env(self):
        self._popen.env = self._get_env()