You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cause of the error
During monkey_patch 'eventlet' doesn't care about constants in built-in 'select' module, that's why patched 'subprocess' module falls back from linux-wide 4096 bytes to default and 'safe' 512 bytes for IO buffer trying to lookup for non-existing constant in 'eventlet.green.select' module:
python3.10/subprocess.py:
# When select or poll has indicated that the file is writable,
# we can write up to _PIPE_BUF bytes without risk of blocking.
# POSIX defines PIPE_BUF as >= 512.
_PIPE_BUF = getattr(select, 'PIPE_BUF', 512)
Steps to reproduce the error
test_write_pipes.py:
import logging
import sys
import time
logging.basicConfig(
stream=sys.stdout, level=logging.DEBUG,
format='[%(asctime)s] %(message)s {%(filename)s:%(lineno)d}')
LOG = logging.getLogger(__name__)
WRITE_CHUNK_SIZE = 64 * (1024 ** 2)
IMAGE_FILE_SIZE = WRITE_CHUNK_SIZE * 2
def image_file_read(chunk_size):
data_len = 0
while data_len < IMAGE_FILE_SIZE:
start_time = time.time()
data = b'*' * chunk_size
LOG.debug(f'Generated in {(time.time() - start_time):.4f} seconds')
yield data
data_len += len(data)
def do_run():
LOG.debug('START')
for image_data in image_file_read(WRITE_CHUNK_SIZE):
args = [
'dd', 'of=./data_file',
]
write_time = time.time()
subprocess.run(
args,
input=image_data,
capture_output=True
)
LOG.debug(f'Written in {(time.time() - write_time):.4f} seconds')
LOG.debug('END')
LOG.debug('===================================')
try:
import subprocess
LOG.debug('Use built-in subprocess and select libraries')
do_run()
finally:
pass
try:
import eventlet
import subprocess
eventlet.monkey_patch()
eventlet_patched = eventlet and eventlet.patcher.is_monkey_patched(
subprocess)
LOG.debug(f'{eventlet_patched=}')
LOG.debug('Use patched by eventlet subprocess and select libraries')
do_run()
finally:
pass
Result:
$ python3 test_write_pipes.py
[2023-10-06 17:42:49,931] Use built-in subprocess and select libraries {test_write_pipes.py:44}
[2023-10-06 17:42:49,931] START {test_write_pipes.py:24}
[2023-10-06 17:42:49,961] Generated in 0.0298 seconds {test_write_pipes.py:18}
[2023-10-06 17:42:49,967] _PIPE_BUF=4096 {subprocess.py:2005}
[2023-10-06 17:42:51,798] Written in 1.8370 seconds {test_write_pipes.py:36}
[2023-10-06 17:42:51,828] Generated in 0.0297 seconds {test_write_pipes.py:18}
[2023-10-06 17:42:51,834] _PIPE_BUF=4096 {subprocess.py:2005}
[2023-10-06 17:42:53,259] Written in 1.4264 seconds {test_write_pipes.py:36}
[2023-10-06 17:42:53,259] END {test_write_pipes.py:38}
[2023-10-06 17:42:53,259] =================================== {test_write_pipes.py:39}
[2023-10-06 17:42:53,490] eventlet_patched=True {test_write_pipes.py:56}
[2023-10-06 17:42:53,490] Use patched by eventlet subprocess and select libraries {test_write_pipes.py:57}
[2023-10-06 17:42:53,490] START {test_write_pipes.py:24}
[2023-10-06 17:42:53,527] Generated in 0.0360 seconds {test_write_pipes.py:18}
[2023-10-06 17:42:53,531] _PIPE_BUF=512 {subprocess.py:2005}
[2023-10-06 17:43:06,731] Written in 13.2037 seconds {test_write_pipes.py:36}
[2023-10-06 17:43:06,760] Generated in 0.0288 seconds {test_write_pipes.py:18}
[2023-10-06 17:43:06,765] _PIPE_BUF=512 {subprocess.py:2005}
[2023-10-06 17:43:19,503] Written in 12.7389 seconds {test_write_pipes.py:36}
[2023-10-06 17:43:19,503] END {test_write_pipes.py:38}
[2023-10-06 17:43:19,503] =================================== {test_write_pipes.py:39}
The text was updated successfully, but these errors were encountered:
Cause of the error
During monkey_patch 'eventlet' doesn't care about constants in built-in 'select' module, that's why patched 'subprocess' module falls back from linux-wide 4096 bytes to default and 'safe' 512 bytes for IO buffer trying to lookup for non-existing constant in 'eventlet.green.select' module:
python3.10/subprocess.py:
Steps to reproduce the error
test_write_pipes.py:
Result:
The text was updated successfully, but these errors were encountered: