-
Notifications
You must be signed in to change notification settings - Fork 165
Fix #1337: Get port info from debugpy #1404
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
import debugpy | ||
from debugpy import adapter, common, launcher | ||
from debugpy.common import json, log, messaging, sockets | ||
from debugpy.adapter import components, servers, sessions | ||
from debugpy.adapter import clients, components, launchers, servers, sessions | ||
|
||
|
||
class Client(components.Component): | ||
|
@@ -110,6 +110,7 @@ def __init__(self, sock): | |
"data": {"packageVersion": debugpy.__version__}, | ||
}, | ||
) | ||
sessions.report_sockets() | ||
|
||
def propagate_after_start(self, event): | ||
# pydevd starts sending events as soon as we connect, but the client doesn't | ||
|
@@ -701,6 +702,24 @@ def disconnect_request(self, request): | |
def disconnect(self): | ||
super().disconnect() | ||
|
||
def report_sockets(self): | ||
sockets = [ | ||
{ | ||
"host": host, | ||
"port": port, | ||
"internal": listener is not clients.listener, | ||
} | ||
for listener in [clients.listener, launchers.listener, servers.listener] | ||
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. What's going on with the lack of indenting in this for loop? 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. This is a Python list comprehension. C# equivalent would be something like: from listener in ...
where listener is ...
let (host, port) = listener.getsockname()
select {...}
.ToList() |
||
if listener is not None | ||
for (host, port) in [listener.getsockname()] | ||
] | ||
self.channel.send_event( | ||
"debugpySockets", | ||
{ | ||
"sockets": sockets | ||
}, | ||
) | ||
|
||
def notify_of_subprocess(self, conn): | ||
log.info("{1} is a subprocess of {0}.", self, conn) | ||
with self.session: | ||
|
@@ -752,11 +771,16 @@ def notify_of_subprocess(self, conn): | |
def serve(host, port): | ||
global listener | ||
listener = sockets.serve("Client", Client, host, port) | ||
sessions.report_sockets() | ||
return listener.getsockname() | ||
|
||
|
||
def stop_serving(): | ||
try: | ||
listener.close() | ||
except Exception: | ||
log.swallow_exception(level="warning") | ||
global listener | ||
if listener is not None: | ||
try: | ||
listener.close() | ||
except Exception: | ||
log.swallow_exception(level="warning") | ||
listener = None | ||
sessions.report_sockets() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm not familiar with this list initialization syntax. Is there supposed to be a comma after the dict? Does the code afterwards resolve to a list and it gets stuffed into the sockets parent list?