Skip to content

Commit

Permalink
Fix race condition in luigi.lock.acquire_for (spotify#2357) (spotify#…
Browse files Browse the repository at this point in the history
  • Loading branch information
StasDeep authored and thisiscab committed Aug 3, 2018
1 parent 756d1e8 commit 361a0f9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 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 @@ -102,10 +103,14 @@ def acquire_for(pid_dir, num_available=1, kill_signal=None):

my_pid, my_cmd, pid_file = get_info(pid_dir)

# Check if there is a pid file corresponding to this name
if not os.path.exists(pid_dir):
# Create a pid file if it does not exist
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 361a0f9

Please sign in to comment.