|
42 | 42 | # We obtain the original, non-patched socket module so that our calls |
43 | 43 | # to the similarity server are truly blocking. |
44 | 44 |
|
| 45 | +import socket |
| 46 | + |
45 | 47 | if TYPE_CHECKING: |
46 | | - import socket |
| 48 | + _original_socket = socket.socket |
47 | 49 | else: |
48 | 50 | try: |
49 | | - # gevent: get the original stdlib socket module |
50 | | - from gevent import monkey as _monkey # type: ignore |
51 | | - socket = _monkey.get_original("socket") # type: ignore |
| 51 | + # gevent: get the original, non-patched socket class |
| 52 | + from gevent.monkey import get_original # type: ignore |
| 53 | + _original_socket = get_original("socket", "socket") |
52 | 54 | except ImportError: |
53 | 55 | try: |
54 | | - # eventlet: get the original stdlib socket module |
| 56 | + # eventlet: get the original, non-patched socket class |
55 | 57 | import eventlet # type: ignore |
56 | | - socket = eventlet.patcher.original("socket") # type: ignore |
| 58 | + _original_socket = eventlet.patcher.original("socket").socket # type: ignore |
57 | 59 | except ImportError: |
58 | | - # No async worker: use the stdlib socket directly |
59 | | - import socket |
| 60 | + # No async worker: stdlib socket is already the original |
| 61 | + _original_socket = socket.socket |
60 | 62 |
|
61 | 63 | # The following two functions replicate and hack/tweak corresponding functions |
62 | 64 | # from multiprocessing.connection. This is necessary because the original |
|
68 | 70 |
|
69 | 71 | def _SocketClient(address: Address) -> Connection: |
70 | 72 | """Return a connection object connected to the socket given by `address`""" |
71 | | - with closing(socket.socket(socket.AF_INET)) as s: |
| 73 | + with closing(_original_socket(socket.AF_INET)) as s: |
72 | 74 | s.setblocking(True) |
73 | 75 | s.connect(address) |
74 | 76 | # The following cast() hack is required since Connection() |
|
0 commit comments