Skip to content

Commit

Permalink
mrtrix3.path.wait_for(): Fix variable ghosting
Browse files Browse the repository at this point in the history
  • Loading branch information
Lestropie committed Aug 17, 2024
1 parent 7935966 commit 9ad39a8
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions lib/mrtrix3/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def in_use(path):
# A fatal error will result in a non-zero code -> in_use() = False, so wait_for() can return
return not subprocess.call(['fuser', '-s', path], shell=False, stdin=None, stdout=None, stderr=None)

def num_exit(data):
def num_exist(data):
count = 0
for entry in data:
if os.path.exists(entry):
Expand Down Expand Up @@ -249,21 +249,25 @@ def num_in_use(data):
app.debug(str(paths))

# Wait until all files exist
num_exist = num_exit(paths)
if num_exist != len(paths):
progress = app.ProgressBar('Waiting for creation of ' + (('new item \"' + paths[0] + '\"') if len(paths) == 1 else (str(len(paths)) + ' new items')), len(paths))
for _ in range(num_exist):
current_num_exist = num_exist(paths)
if current_num_exist != len(paths):
progress = app.ProgressBar('Waiting for creation of ' \
+ (('new item \"' + paths[0] + '\"') \
if len(paths) == 1 \
else (str(len(paths)) + ' new items')),
len(paths))
for _ in range(current_num_exist):
progress.increment()
delay = 1.0/1024.0
while not num_exist == len(paths):
while not current_num_exist == len(paths):
time.sleep(delay)
new_num_exist = num_exit(paths)
if new_num_exist == num_exist:
new_num_exist = num_exist(paths)
if new_num_exist == current_num_exist:
delay = max(60.0, delay*2.0)
elif new_num_exist > num_exist:
for _ in range(new_num_exist - num_exist):
elif new_num_exist > current_num_exist:
for _ in range(new_num_exist - current_num_exist):
progress.increment()
num_exist = new_num_exist
current_num_exist = new_num_exist
delay = 1.0/1024.0
progress.done()
else:
Expand All @@ -280,28 +284,31 @@ def num_in_use(data):
return

# Can we query the in-use status of any of these paths
num_in_use = num_in_use(paths)
if num_in_use is None:
current_num_in_use = num_in_use(paths)
if current_num_in_use is None:
app.debug('Unable to test for finalization of new files')
return

# Wait until all files are not in use
if not num_in_use:
if not current_num_in_use:
app.debug('Item' + ('s' if len(paths) > 1 else '') + ' immediately ready')
return

progress = app.ProgressBar('Waiting for finalization of ' + (('new file \"' + paths[0] + '\"') if len(paths) == 1 else (str(len(paths)) + ' new files')))
for _ in range(len(paths) - num_in_use):
progress = app.ProgressBar('Waiting for finalization of '
+ (('new file \"' + paths[0] + '\"') \
if len(paths) == 1 \
else (str(len(paths)) + ' new files')))
for _ in range(len(paths) - current_num_in_use):
progress.increment()
delay = 1.0/1024.0
while num_in_use:
while current_num_in_use:
time.sleep(delay)
new_num_in_use = num_in_use(paths)
if new_num_in_use == num_in_use:
if new_num_in_use == current_num_in_use:
delay = max(60.0, delay*2.0)
elif new_num_in_use < num_in_use:
for _ in range(num_in_use - new_num_in_use):
elif new_num_in_use < current_num_in_use:
for _ in range(current_num_in_use - new_num_in_use):
progress.increment()
num_in_use = new_num_in_use
current_num_in_use = new_num_in_use
delay = 1.0/1024.0
progress.done()

0 comments on commit 9ad39a8

Please sign in to comment.