MCPcopy
hub / github.com/celery/celery / Rdb

Class Rdb

celery/contrib/rdb.py:84–172  ·  view source on GitHub ↗

Remote debugger.

Source from the content-addressed store, hash-verified

82
83
84class Rdb(Pdb):
85 """Remote debugger."""
86
87 me = 'Remote Debugger'
88 _prev_outs = None
89 _sock = None
90
91 def __init__(self, host=CELERY_RDB_HOST, port=CELERY_RDB_PORT,
92 port_search_limit=100, port_skew=+0, out=sys.stdout):
93 self.active = True
94 self.out = out
95
96 self._prev_handles = sys.stdin, sys.stdout
97
98 self._sock, this_port = self.get_avail_port(
99 host, port, port_search_limit, port_skew,
100 )
101 self._sock.setblocking(1)
102 self._sock.listen(1)
103 self.ident = f'{self.me}:{this_port}'
104 self.host = host
105 self.port = this_port
106 self.say(BANNER.format(self=self))
107
108 self._client, address = self._sock.accept()
109 self._client.setblocking(1)
110 self.remote_addr = ':'.join(str(v) for v in address)
111 self.say(SESSION_STARTED.format(self=self))
112 self._handle = sys.stdin = sys.stdout = self._client.makefile('rw')
113 super().__init__(completekey='tab',
114 stdin=self._handle, stdout=self._handle)
115
116 def get_avail_port(self, host, port, search_limit=100, skew=+0):
117 try:
118 _, skew = current_process().name.split('-')
119 skew = int(skew)
120 except ValueError:
121 pass
122 this_port = None
123 for i in range(search_limit):
124 _sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
125 _sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
126 this_port = port + skew + i
127 try:
128 _sock.bind((host, this_port))
129 except OSError as exc:
130 if exc.errno in [errno.EADDRINUSE, errno.EINVAL]:
131 continue
132 raise
133 else:
134 return _sock, this_port
135 raise Exception(NO_AVAILABLE_PORT.format(self=self))
136
137 def say(self, m):
138 print(m, file=self.out)
139
140 def __enter__(self):
141 return self

Callers 3

test_rdbMethod · 0.90
test_get_avail_portMethod · 0.90
debuggerFunction · 0.85

Calls

no outgoing calls

Tested by 2

test_rdbMethod · 0.72
test_get_avail_portMethod · 0.72