Skip to content

Commit

Permalink
Fix "Bad file descriptor"
Browse files Browse the repository at this point in the history
Somehow aliasing _read to conn._read breaks it, even though it's not a
class method.
  • Loading branch information
alecmev committed Aug 9, 2022
1 parent f14e088 commit 6ab3fca
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
8 changes: 3 additions & 5 deletions plugin/core/transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,12 @@ class NodeIpcIO():
_lines = 0

def __init__(self, conn: multiprocessing.connection._ConnectionBase):
self._fd = conn.fileno()
self._read = conn._read # type: ignore
self._write = conn._write # type: ignore
self._conn = conn

# https://github.com/python/cpython/blob/330f1d58282517bdf1f19577ab9317fa9810bf95/Lib/multiprocessing/connection.py#L378-L392
def readline(self) -> bytearray:
while self._lines == 0:
chunk = self._read(self._fd, 65536) # type: bytes
chunk = self._conn._read(self._conn.fileno(), 65536) # type: ignore
self._buf += chunk
self._lines += chunk.count(b'\n')

Expand All @@ -255,7 +253,7 @@ def readline(self) -> bytearray:
# https://github.com/python/cpython/blob/330f1d58282517bdf1f19577ab9317fa9810bf95/Lib/multiprocessing/connection.py#L369-L376
def write(self, data: bytes) -> None:
while len(data):
n = self._write(self._fd, data) # type: int
n = self._conn._write(self._conn.fileno(), data) # type: ignore
data = data[n:]


Expand Down
1 change: 0 additions & 1 deletion plugin/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import contextlib
import fnmatch
import multiprocessing
import multiprocessing.connection
import os
import posixpath
import socket
Expand Down

0 comments on commit 6ab3fca

Please sign in to comment.