MCPcopy Create free account
hub / github.com/microsoft/debugpy / from_socket

Method from_socket

src/debugpy/common/messaging.py:89–109  ·  view source on GitHub ↗

Creates a new instance that sends and receives messages over a socket.

(cls, sock, name=None)

Source from the content-addressed store, hash-verified

87
88 @classmethod
89 def from_socket(cls, sock, name=None):
90 """Creates a new instance that sends and receives messages over a socket."""
91 sock.settimeout(None) # make socket blocking
92 if name is None:
93 name = repr(sock)
94
95 # TODO: investigate switching to buffered sockets; readline() on unbuffered
96 # sockets is very slow! Although the implementation of readline() itself is
97 # native code, it calls read(1) in a loop - and that then ultimately calls
98 # SocketIO.readinto(), which is implemented in Python.
99 socket_io = sock.makefile("rwb", 0)
100
101 # SocketIO.close() doesn't close the underlying socket.
102 def cleanup():
103 try:
104 sock.shutdown(socket.SHUT_RDWR)
105 except Exception: # pragma: no cover
106 pass
107 sock.close()
108
109 return cls(socket_io, socket_io, name, cleanup)
110
111 def __init__(self, reader, writer, name=None, cleanup=lambda: None):
112 """Creates a new JsonIOStream.

Callers 7

connectFunction · 0.80
on_launcher_connectedFunction · 0.80
__init__Method · 0.80
__init__Method · 0.80
_setup_streamMethod · 0.80
connect_to_adapterMethod · 0.80
backchannel.pyFile · 0.80

Calls 1

reprFunction · 0.85

Tested by

no test coverage detected