Commit 3c0ffcff authored by Franziska Koehn's avatar Franziska Koehn
Browse files

download via threads

parent 92e615f0
HOST = None
from threading import Lock
requests_lock = Lock()
def main(host):
import distutils.core
......@@ -58,14 +61,16 @@ def download_all(results, host=None):
for r in results:
download(r, host)
def download_f(*args, **kwargs):
download(*args, **kwargs)
# if this does not return False, the function will be repeatedly called by timeout_add
return False
def download_async(result, host=None, cb=(lambda *_: None), cb_args=()):
from threading import Thread
download_thread = Thread(target=download, args=(result, host, cb, cb_args))
download_thread.start()
return download_thread
def download(result, host=None):
def download(result, host=None, cb=(lambda *_: None), cb_args=()):
if not host:
host = HOST
requests_lock.acquire()
print(result)
subject = result['xnat_mrsessiondata_subject_id']
experiment = result['xnat_mrsessiondata_session_id']
......@@ -73,6 +78,8 @@ def download(result, host=None):
scan = result['id']
file_name = "%s_%s_%s" % (subject, result['type'], scan)
download_file(host, project, subject, experiment, scan, file_name)
requests_lock.release()
cb(*cb_args)
def search_for_mrScanData(host, constraints, user, passw):
get_credentials(username=user, password=passw, force=True)
......
......@@ -192,4 +192,5 @@ class treeViewChartValues(gtk.TreeView):
XnatSearchApp()
gtk.gdk.threads_init()
gtk.main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment