@@ -59,6 +59,13 @@ cdef class Transport:
5959 f" {operation} [op {self._op_num}] on socket {self._transport_num}"
6060 )
6161
62+ cdef int _print_output(self , str text) except - 1 :
63+ """
64+ Prints and flushes the text to stdout to ensure that multiple
65+ threads don't lose output due to buffering.
66+ """
67+ print (text + " \n " , flush= True )
68+
6269 cdef int _print_packet(self , str operation, object data) except - 1 :
6370 """
6471 Print the packet content in a format suitable for debugging.
@@ -89,16 +96,17 @@ cdef class Transport:
8996 f' |{"".join(printable_values)}|'
9097 )
9198 offset += 8
92- output_lines.append(" " )
93- print (" \n " .join(output_lines))
99+ self ._print_output(" \n " .join(output_lines))
94100
95101 cdef int disconnect(self ) except - 1 :
96102 """
97103 Disconnects the transport.
98104 """
99105 if self ._transport is not None :
100106 if DEBUG_PACKETS:
101- print (self ._get_debugging_header(" Disconnecting transport" ))
107+ self ._print_output(
108+ self ._get_debugging_header(" Disconnecting transport" )
109+ )
102110 self ._transport.close()
103111 self ._transport = None
104112
@@ -268,8 +276,9 @@ cdef class Transport:
268276 Sends an out-of-band break on the transport.
269277 """
270278 if DEBUG_PACKETS:
271- print (self ._get_debugging_header(" Sending out of band break" ))
272- print ()
279+ self ._print_output(
280+ self ._get_debugging_header(" Sending out of band break" )
281+ )
273282 self ._transport.send(b" !" , socket.MSG_OOB)
274283
275284 cdef int set_from_socket(self , object transport,
0 commit comments