提交 7ec197e7 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Fix lock for python 3

上级 3b51141a
...@@ -7,6 +7,7 @@ import os ...@@ -7,6 +7,7 @@ import os
import socket # only used for gethostname() import socket # only used for gethostname()
import time import time
import logging import logging
from six import PY3
from contextlib import contextmanager from contextlib import contextmanager
...@@ -271,9 +272,14 @@ def lock(tmp_dir, timeout=notset, min_wait=None, max_wait=None, verbosity=1): ...@@ -271,9 +272,14 @@ def lock(tmp_dir, timeout=notset, min_wait=None, max_wait=None, verbosity=1):
nb_wait += 1 nb_wait += 1
time.sleep(random.uniform(min_wait, max_wait)) time.sleep(random.uniform(min_wait, max_wait))
if PY3:
exception = FileExistsError
else:
exception = OSError
try: try:
os.mkdir(tmp_dir) os.mkdir(tmp_dir)
except OSError: except exception:
# Error while creating the directory: someone else # Error while creating the directory: someone else
# must have tried at the exact same time. # must have tried at the exact same time.
nb_error += 1 nb_error += 1
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论