Repository navigation
Rewrite IPC to use multiprocessing.connection #6010
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,8 +200,8 @@ def serve(self) -> None: | |
| json.dump({'pid': os.getpid(), 'connection_name': server.connection_name}, f) | ||
| f.write('\n') # I like my JSON with a trailing newline | ||
| while True: | ||
| with server: | ||
| data = receive(server) | ||
| with server as connection: | ||
| data = receive(connection) | ||
| resp = {} # type: Dict[str, Any] | ||
| if 'command' not in data: | ||
| resp = {'error': "No command found in request"} | ||
|
|
@@ -217,10 +217,10 @@ def serve(self) -> None: | |
| # If we are crashing, report the crash to the client | ||
| tb = traceback.format_exception(*sys.exc_info()) | ||
| resp = {'error': "Daemon crashed!\n" + "".join(tb)} | ||
| server.write(json.dumps(resp).encode('utf8')) | ||
| connection.send_bytes(json.dumps(resp).encode('utf8')) | ||
| raise | ||
| try: | ||
| server.write(json.dumps(resp).encode('utf8')) | ||
| connection.send_bytes(json.dumps(resp).encode('utf8')) | ||
| except OSError: | ||
| pass # Maybe the client hung up | ||
| if command == 'stop': | ||
|
|
@@ -232,12 +232,9 @@ def serve(self) -> None: | |
| # simplify the logic and always remove the file, since | ||
| # that could cause us to remove a future server's | ||
| # status file.) | ||
| server.close() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sully had a specific reason for the ordering of the closing of the socket and the unlinking of the status file; if you close the socket first, it's possible for a new client to start a new server before we get to remove the status file, and then we'd end up removing the wrong status file. See #5956.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in this case it is just cleanliness. The bug fix was doing the file removal in |
||
| if command != 'stop': | ||
| os.unlink(STATUS_FILE) | ||
| try: | ||
| server.cleanup() # try to remove the socket dir on Linux | ||
| except OSError: | ||
| pass | ||
| exc_info = sys.exc_info() | ||
| if exc_info[0] and exc_info[0] is not SystemExit: | ||
| traceback.print_exception(*exc_info) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These semantics of
__enter__are a little too magical. I'd prefer to see something likewith server.accept_connection() as connectionhere.