MCPcopy
hub / github.com/celery/celery / ignore_errno

Function ignore_errno

celery/platforms.py:760–785  ·  view source on GitHub ↗

Context manager to ignore specific POSIX error codes. Takes a list of error codes to ignore: this can be either the name of the code, or the code integer itself:: >>> with ignore_errno('ENOENT'): ... with open('foo', 'r') as fh: ... return fh.read()

(*errnos, **kwargs)

Source from the content-addressed store, hash-verified

758
759@contextmanager
760def ignore_errno(*errnos, **kwargs):
761 """Context manager to ignore specific POSIX error codes.
762
763 Takes a list of error codes to ignore: this can be either
764 the name of the code, or the code integer itself::
765
766 >>> with ignore_errno('ENOENT'):
767 ... with open('foo', 'r') as fh:
768 ... return fh.read()
769
770 >>> with ignore_errno(errno.ENOENT, errno.EPERM):
771 ... pass
772
773 Arguments:
774 types (Tuple[Exception]): A tuple of exceptions to ignore
775 (when the errno matches). Defaults to :exc:`Exception`.
776 """
777 types = kwargs.get('types') or (Exception,)
778 errnos = [get_errno_name(errno) for errno in errnos]
779 try:
780 yield
781 except types as exc:
782 if not hasattr(exc, 'errno'):
783 raise
784 if exc.errno not in errnos:
785 raise
786
787
788def check_privileges(accept_content):

Callers 4

test_raises_EBADFMethod · 0.90
test_otherwiseMethod · 0.90
read_pidMethod · 0.85
removeMethod · 0.85

Calls 2

get_errno_nameFunction · 0.85
getMethod · 0.45

Tested by 2

test_raises_EBADFMethod · 0.72
test_otherwiseMethod · 0.72