Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mrtrix3.path.wait_for(): Fix variable ghosting #2968

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 30 additions & 23 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:
delay = max(60.0, delay*2.0)
elif new_num_exist > num_exist:
for _ in range(new_num_exist - num_exist):
new_num_exist = num_exist(paths)
if new_num_exist == current_num_exist:
delay = min(60.0, delay*2.0)
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:
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):
if new_num_in_use == current_num_in_use:
delay = min(60.0, delay*2.0)
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()
Loading