Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
isidentical opened this issue Oct 7, 2022 · 0 comments

Comments

@isidentical
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant