Skip to content

Commit

Permalink
refactor: replace IOError with OSError
Browse files Browse the repository at this point in the history
  • Loading branch information
e-kwsm committed Mar 23, 2024
1 parent 88fc4a4 commit d58db49
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/when_ready.conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, server, max_mem):
def memory_usage(self, pid):
try:
out = commands.getoutput("ps -o rss -p %s" % pid)
except IOError:
except OSError:
return -1
used_mem = sum(int(x) for x in out.split('\n')[1:])
return used_mem
Expand Down
2 changes: 1 addition & 1 deletion gunicorn/arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def wakeup(self):
"""
try:
os.write(self.PIPE[1], b'.')
except IOError as e:
except OSError as e:
if e.errno not in [errno.EAGAIN, errno.EINTR]:
raise

Expand Down
2 changes: 1 addition & 1 deletion gunicorn/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __call__(self, frame, event, arg):
try:
src = inspect.getsourcelines(frame)
line = src[lineno]
except IOError:
except OSError:
line = 'Unknown code named [%s]. VM instruction #%d' % (
frame.f_code.co_name, frame.f_lasti)
if self.trace_names is None or name in self.trace_names:
Expand Down
6 changes: 3 additions & 3 deletions gunicorn/http/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ParseException(Exception):
pass


class NoMoreData(IOError):
class NoMoreData(OSError):
def __init__(self, buf=None):
self.buf = buf

Expand Down Expand Up @@ -82,15 +82,15 @@ def __str__(self):
return "Unsupported transfer coding: %r" % self.hdr


class InvalidChunkSize(IOError):
class InvalidChunkSize(OSError):
def __init__(self, data):
self.data = data

def __str__(self):
return "Invalid chunk size: %r" % self.data


class ChunkMissingTerminator(IOError):
class ChunkMissingTerminator(OSError):
def __init__(self, term):
self.term = term

Expand Down
2 changes: 1 addition & 1 deletion gunicorn/pidfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def validate(self):
if e.args[0] == errno.ESRCH:
return
raise
except IOError as e:
except OSError as e:
if e.args[0] == errno.ENOENT:
return
raise
4 changes: 2 additions & 2 deletions gunicorn/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def check_is_writable(path):
try:
with open(path, 'a') as f:
f.close()
except IOError as e:
except OSError as e:
raise RuntimeError("Error: '%s' isn't writable [%r]" % (path, e))


Expand All @@ -587,7 +587,7 @@ def has_fileno(obj):
# check BytesIO case and maybe others
try:
obj.fileno()
except (AttributeError, IOError, io.UnsupportedOperation):
except (AttributeError, OSError, io.UnsupportedOperation):
return False

return True
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pidfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def builtin(name):
@mock.patch(builtin('open'), new_callable=mock.mock_open)
def test_validate_no_file(_open):
pidfile = gunicorn.pidfile.Pidfile('test.pid')
_open.side_effect = IOError(errno.ENOENT)
_open.side_effect = OSError(errno.ENOENT)
assert pidfile.validate() is None


Expand Down

0 comments on commit d58db49

Please sign in to comment.