MCPcopy Index your code
hub / github.com/fabioz/PyDev.Debugger / WriterThread

Class WriterThread

_pydevd_bundle/pydevd_comm.py:363–448  ·  view source on GitHub ↗

writer thread writes out the commands in an infinite loop

Source from the content-addressed store, hash-verified

361
362
363class WriterThread(PyDBDaemonThread):
364 """writer thread writes out the commands in an infinite loop"""
365
366 def __init__(self, sock, py_db, terminate_on_socket_close=True):
367 PyDBDaemonThread.__init__(self, py_db)
368 self.sock = sock
369 self.__terminate_on_socket_close = terminate_on_socket_close
370 self.name = "pydevd.Writer"
371 self._cmd_queue = _queue.Queue()
372 if pydevd_vm_type.get_vm_type() == "python":
373 self.timeout = 0
374 else:
375 self.timeout = 0.1
376
377 def add_command(self, cmd):
378 """cmd is NetCommand"""
379 if not self._kill_received: # we don't take new data after everybody die
380 self._cmd_queue.put(cmd, False)
381
382 @overrides(PyDBDaemonThread._on_run)
383 def _on_run(self):
384 """just loop and write responses"""
385
386 try:
387 while True:
388 try:
389 try:
390 cmd = self._cmd_queue.get(True, 0.1)
391 except _queue.Empty:
392 if self._kill_received:
393 pydev_log.debug("WriterThread: kill_received (sock.shutdown(SHUT_WR))")
394 try:
395 self.sock.shutdown(SHUT_WR)
396 except:
397 pass
398 # Note: don't close the socket, just send the shutdown,
399 # then, when no data is received on the reader, it can close
400 # the socket.
401 # See: https://blog.netherlabs.nl/articles/2009/01/18/the-ultimate-so_linger-page-or-why-is-my-tcp-not-reliable
402
403 # try:
404 # self.sock.close()
405 # except:
406 # pass
407
408 return # break if queue is empty and _kill_received
409 else:
410 continue
411 except:
412 # pydev_log.info('Finishing debug communication...(1)')
413 # when liberating the thread here, we could have errors because we were shutting down
414 # but the thread was still not liberated
415 return
416
417 if cmd.as_dict is not None:
418 for listener in self.py_db.dap_messages_listeners:
419 listener.before_send(cmd.as_dict)
420

Callers 2

initialize_networkMethod · 0.90
_locked_settraceFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected