@@ -59,6 +59,13 @@ cdef class Transport:
59
59
f" {operation} [op {self._op_num}] on socket {self._transport_num}"
60
60
)
61
61
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
+
62
69
cdef int _print_packet(self , str operation, object data) except - 1 :
63
70
"""
64
71
Print the packet content in a format suitable for debugging.
@@ -89,16 +96,17 @@ cdef class Transport:
89
96
f' |{"".join(printable_values)}|'
90
97
)
91
98
offset += 8
92
- output_lines.append(" " )
93
- print (" \n " .join(output_lines))
99
+ self ._print_output(" \n " .join(output_lines))
94
100
95
101
cdef int disconnect(self ) except - 1 :
96
102
"""
97
103
Disconnects the transport.
98
104
"""
99
105
if self ._transport is not None :
100
106
if DEBUG_PACKETS:
101
- print (self ._get_debugging_header(" Disconnecting transport" ))
107
+ self ._print_output(
108
+ self ._get_debugging_header(" Disconnecting transport" )
109
+ )
102
110
self ._transport.close()
103
111
self ._transport = None
104
112
@@ -268,8 +276,9 @@ cdef class Transport:
268
276
Sends an out-of-band break on the transport.
269
277
"""
270
278
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
+ )
273
282
self ._transport.send(b" !" , socket.MSG_OOB)
274
283
275
284
cdef int set_from_socket(self , object transport,
0 commit comments