예제 #1
0
 def __init__(self, msg):
     if isinstance(msg, str):
         # used by rpc when reraising the exception on the caller side
         super().__init__(msg)
     else:
         tb = ExceptionWithTraceback(msg).tb
         super().__init__(tb)
예제 #2
0
    def _worker(cmd_queue: SimpleQueue, result_queue: SimpleQueue, env_creator,
                env_idx):
        env = None
        try:
            env = dill.loads(env_creator)(env_idx)
        except Exception:
            # Something has gone wrong during environment creation,
            # exit with error.
            exit(2)
        try:
            while True:
                try:
                    command = cmd_queue.quick_get(timeout=1e-3)
                except TimeoutError:
                    continue

                try:
                    if command is not None:
                        method, args, kwargs = command
                    else:
                        # End of all tasks signal received
                        cmd_queue.close()
                        result_queue.close()
                        break
                    result = getattr(env, method)(*args, **kwargs)
                    result_queue.put((env_idx, True, result))
                except Exception as e:
                    # Something has gone wrong during execution, serialize
                    # the exception and send it back to master.
                    result_queue.put(
                        (env_idx, False, ExceptionWithTraceback(e)))
        except KeyboardInterrupt:
            cmd_queue.close()
            result_queue.close()