Skip to content

Commit 3fbee66

Browse files
Packet output is now immediately flushed in order to avoid losing output
due to buffering when multiple threads are running.
1 parent 40d2b97 commit 3fbee66

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Thin Mode Changes
1717
name containing ``%ROWTYPE``
1818
(`issue 304 <https://github.com/oracle/python-oracledb/issues/304>`__).
1919
#) Tightened up code looking for the end of a database request.
20+
#) Packet output is now immediately flushed in order to avoid losing output
21+
due to buffering when multiple threads are running.
2022
#) Restored error message raised when attempting to connect to Oracle Database
2123
11g.
2224

src/oracledb/impl/thin/transport.pyx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)