Skip to content

Commit

Permalink
Work around for jupyter/notebook#6721
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhartl authored Jul 6, 2023
1 parent 6e3521d commit f8afa2d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tornado/iostream.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import ssl
import sys
import re
import threading

from tornado.concurrent import Future, future_set_result_unless_cancelled
from tornado import ioloop
Expand Down Expand Up @@ -278,6 +279,7 @@ def __init__(
self._connecting = False
self._state = None # type: Optional[int]
self._closed = False
self._write_lock = threading.Lock()

def fileno(self) -> Union[int, ioloop._Selectable]:
"""Returns the file descriptor for this stream."""
Expand Down Expand Up @@ -959,10 +961,11 @@ def _handle_write(self) -> None:
# with more than 128KB at a time.
size = 128 * 1024

num_bytes = self.write_to_fd(self._write_buffer.peek(size))
if num_bytes == 0:
break
self._write_buffer.advance(num_bytes)
with self._write_lock:
num_bytes = self.write_to_fd(self._write_buffer.peek(size))
if num_bytes == 0:
break
self._write_buffer.advance(num_bytes)
self._total_write_done_index += num_bytes
except BlockingIOError:
break
Expand Down

0 comments on commit f8afa2d

Please sign in to comment.