Use OSError subclasses instead of handling errno

This commit is contained in:
Bruno Oliveira
2019-08-01 20:55:30 -03:00
committed by Bruno Oliveira
parent dc6e7b9fcf
commit d3e1907899
4 changed files with 73 additions and 27 deletions

View File

@@ -1,5 +1,4 @@
import atexit
import errno
import fnmatch
import itertools
import operator
@@ -151,14 +150,8 @@ def create_cleanup_lock(p):
lock_path = get_lock_path(p)
try:
fd = os.open(str(lock_path), os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o644)
except OSError as e:
if e.errno == errno.EEXIST:
raise EnvironmentError(
"cannot create lockfile in {path}".format(path=p)
) from e
else:
raise
except FileExistsError as e:
raise EnvironmentError("cannot create lockfile in {path}".format(path=p)) from e
else:
pid = os.getpid()
spid = str(pid).encode()