Skip to content

Commit

Permalink
Fix race condition in luigi.lock.acquire_for (#2357)
Browse files Browse the repository at this point in the history
  • Loading branch information
StasDeep committed Jul 30, 2018
1 parent 7d2c557 commit 0e5e25a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions luigi/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"""
from __future__ import print_function

import errno
import hashlib
import os
import sys
Expand Down Expand Up @@ -104,8 +105,14 @@ def acquire_for(pid_dir, num_available=1, kill_signal=None):

# Check if there is a pid file corresponding to this name
if not os.path.exists(pid_dir):
os.mkdir(pid_dir)
os.chmod(pid_dir, 0o777)
# Try/except for handling race condition
try:
os.mkdir(pid_dir)
os.chmod(pid_dir, 0o777)
except OSError as exc:
if exc.errno != errno.EEXIST:
raise
pass

# Let variable "pids" be all pids who exist in the .pid-file who are still
# about running the same command.
Expand Down

0 comments on commit 0e5e25a

Please sign in to comment.