Example #1
0
    def _worker(
        cmd_queue: SimpleQueue, result_queue: SimpleQueue, env_creator, env_idx
    ):
        env = None
        try:
            env = 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()
Example #2
0
def test_dumps_local_func():
    pipe_0, pipe_1 = Pipe(duplex=True)
    ctx = get_context("fork")
    process_0 = Process(target=subproc_test_dumps_local_func,
                        args=(pipe_0, ),
                        ctx=ctx)
    process_0.start()
    while process_0.is_alive():
        process_0.watch()
    assert t.all(loads(pipe_1.recv())() == t.zeros([10]))
    process_0.join()
Example #3
0
def print_tensor_sub_proc(tens):
    print(loads(tens))
Example #4
0
def exec_sub_proc(func):
    loads(func)()