Skip to content

Commit ed146e5

Browse files
committed
apply @mgxd 's suggestions, adding a warning and a timeout environment variable
1 parent 7c58aad commit ed146e5

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

heudiconv/convert.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from filelock import SoftFileLock
1+
import filelock
22
import os
33
import os.path as op
44
import logging
@@ -34,7 +34,6 @@
3434
)
3535

3636
LOCKFILE = 'heudiconv.lock'
37-
LOCKFILE_TIMEOUT = 10
3837
lgr = logging.getLogger(__name__)
3938

4039

@@ -205,8 +204,15 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
205204
clear_temp_dicoms(item_dicoms)
206205

207206
if bids:
208-
with SoftFileLock(op.join(anon_outdir, LOCKFILE),
209-
timeout=LOCKFILE_TIMEOUT):
207+
lockfile = op.join(anon_outdir, LOCKFILE)
208+
if op.exists(lockfile):
209+
lgr.warning("Existing lockfile found in {0} - waiting for the "
210+
"lock to be released. To set a timeout limit, set "
211+
"the HEUDICONV_FILELOCK_TIMEOUT environmental variable "
212+
"to a value in seconds. If this process hangs, it may "
213+
"require a manual deletion of the {0}.".format(lockfile))
214+
timeout = os.environ.get("HEUDICONV_LOCKFILE_TIMEOUT", -1)
215+
with filelock.SoftFileLock(lockfile, timeout=timeout):
210216
if seqinfo:
211217
keys = list(seqinfo)
212218
add_participant_record(anon_outdir,

0 commit comments

Comments
 (0)