Skip to content

Make isolate re-use the same agent as long as the connection is open #7

Open
@isidentical

Description

@isidentical

In the current implementation, we just receive a single callable, call it, and exit from the agent. But since each connection can actually execute multiple callables, it is really inefficient to re-start the agent process for no reason.

# TODO(feat): this should probably run in a loop instead of
# receiving a single function and then exitting immediately.
with child_connection(serialization_backend_name, address) as connection:
print(f"[trace] Created child connection to {address}")
callable = connection.recv()
print(f"[trace] Received the callable at {address}")
result = None
did_it_raise = False
try:
result = callable()
except BaseException as exc:
result = exc
did_it_raise = True
finally:
try:
connection.send((result, did_it_raise))
except BaseException:
if did_it_raise:
# If we can't even send it through the connection
# still try to dump it to the stderr as the last
# resort.
import traceback
assert isinstance(result, BaseException)
traceback.print_exception(
type(result),
result,
result.__traceback__,
)
raise

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions