Skip to content

Commit

Permalink
fix: Backwards compat with older versions of zmq
Browse files Browse the repository at this point in the history
zmq.ROUTING_ID was added in libzmq 4.2.3 as an alias for IDENTITY.
  • Loading branch information
Marc Udoff committed May 10, 2021
1 parent d210ad1 commit cf0e43a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ipykernel/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
from IPython.core.getipython import get_ipython
import debugpy

# Required for backwards compatiblity
ROUTING_ID = getattr(zmq, 'ROUTING_ID', None) or zmq.IDENTITY

class DebugpyMessageQueue:

HEADER = 'Content-Length: '
Expand Down Expand Up @@ -119,7 +122,7 @@ def _forward_event(self, msg):

def _send_request(self, msg):
if self.routing_id is None:
self.routing_id = self.debugpy_stream.socket.getsockopt(zmq.ROUTING_ID)
self.routing_id = self.debugpy_stream.socket.getsockopt(ROUTING_ID)
content = jsonapi.dumps(msg)
content_length = str(len(content))
buf = (DebugpyMessageQueue.HEADER + content_length + DebugpyMessageQueue.SEPARATOR).encode('ascii')
Expand Down Expand Up @@ -166,7 +169,7 @@ def get_host_port(self):

def connect_tcp_socket(self):
self.debugpy_stream.socket.connect(self._get_endpoint())
self.routing_id = self.debugpy_stream.socket.getsockopt(zmq.ROUTING_ID)
self.routing_id = self.debugpy_stream.socket.getsockopt(ROUTING_ID)

def disconnect_tcp_socket(self):
self.debugpy_stream.socket.disconnect(self._get_endpoint())
Expand Down Expand Up @@ -260,7 +263,7 @@ def start(self):
'silent': True
}
self.session.send(self.shell_socket, 'execute_request', content,
None, (self.shell_socket.getsockopt(zmq.ROUTING_ID)))
None, (self.shell_socket.getsockopt(ROUTING_ID)))

ident, msg = self.session.recv(self.shell_socket, mode=0)
self.debugpy_initialized = msg['content']['status'] == 'ok'
Expand Down

0 comments on commit cf0e43a

Please sign in to comment.