Skip to content

Commit 95b6f40

Browse files
d-w-mooretrel
authored andcommitted
[#358] eliminate fcntl import
The fcntl module does not exist on Windows.
1 parent e7b6ece commit 95b6f40

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

irods/message/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from . import quasixml as ET_quasi_xml
1313
from collections import namedtuple
1414
import os
15-
import fcntl
1615
import ast
1716
import threading
1817
from irods.message.message import Message
@@ -153,7 +152,15 @@ def ET(xml_type = 0, server_version = None):
153152

154153

155154
# Necessary for older python (<3.7):
156-
_socket_is_blocking = (lambda self: 0 == fcntl.fcntl(self.fileno(), fcntl.F_GETFL) & os.O_NONBLOCK)
155+
156+
def _socket_is_blocking(sk):
157+
try:
158+
return sk.getblocking()
159+
except AttributeError:
160+
# Python 3.7+ docs say sock.getblocking() is equivalent to checking if sock.gettimeout() == 0, but this is misleading.
161+
# Manual testing shows this to be a more accurate equivalent:
162+
timeout = sk.gettimeout()
163+
return (timeout is None or timeout > 0)
157164

158165
def _recv_message_in_len(sock, size):
159166
size_left = size

0 commit comments

Comments
 (0)