Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix upmap-remapped script to avoid BlockingIOError #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Taadas
Copy link

@Taadas Taadas commented Dec 23, 2024

Before this fix, the script sometimes would raise a BlockingIOError when trying to execute subprocess.getoutput:

Traceback (most recent call last):
  File "/usr/bin/ceph", line 1327, in <module>
    retval = main()
             ^^^^^^
  File "/usr/bin/ceph", line 1294, in main
    raise e
  File "/usr/bin/ceph", line 1290, in main
    raw_write(outbuf)
  File "/usr/bin/ceph", line 172, in raw_write
    sys.stdout.buffer.write(buf)
BlockingIOError: [Errno 11] write could not complete without blocking

This was due to the fact that the script blocked the standard output of the subprocess, which caused the error. This fix changes the script to use subprocess.run instead of subprocess.getoutput to avoid the error.

@laimis9133
Copy link

laimis9133 commented Dec 23, 2024

BlockingIOError issues observed when switching from Python 3.9.2 to 3.11.2, great fix!
Also fixes an old closed issue: #29

@@ -40,6 +40,10 @@

import json, subprocess, sys

def get_command_output(command):
result = subprocess.run(command, capture_output=True, text=True, check=True, shell=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Taadas thanks for this PR.

text=True will break compat with Python < 3.7 https://stackoverflow.com/questions/52663518/python-subprocess-popen-doesnt-take-text-argument

universal_newlines=True should work for old and current Pythons.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, changed to universal_newlines.

Before this fix, the script sometimes would raise a BlockingIOError when
trying to execute `subprocess.getoutput`. This was due to the fact that the
script blocked the standard output of the subprocess, which caused the error.
This fix changes the script to use `subprocess.run` instead of
`subprocess.getoutput` to avoid the error.
@Taadas Taadas force-pushed the bugfix/upmap-remapped-io-error branch from e5926dc to b579703 Compare February 21, 2025 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants