Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
onekiloparsec committed May 6, 2020
2 parents d53ed7f + a7aa0c2 commit 46f0445
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion arcsecond/__init__.py
Expand Up @@ -7,4 +7,4 @@
"ArcsecondConnectionError",
"ArcsecondInvalidEndpointError"]

__version__ = '0.9.4'
__version__ = '0.9.5'
16 changes: 10 additions & 6 deletions arcsecond/api/endpoints/_fileuploader.py
Expand Up @@ -28,12 +28,14 @@ def __init__(self, url, method, data=None, payload=None, **headers):
self.headers = headers
self._storage = {}
self._thread = None
self._has_run = False

def start(self):
if self._thread is None:
args = (self.url, self.method, self.data, self.payload, self.headers)
self._thread = threading.Thread(target=self._target, args=args)
if self._thread.is_alive() is False:
self._has_run = True
self._thread.start()

def _target(self, url, method, data, payload, headers):
Expand All @@ -45,17 +47,19 @@ def _target(self, url, method, data, payload, headers):
self._storage['error'] = ArcsecondError(str(e))

def finish(self):
self.join()
# I haven't found yet why self._thread can be None when target is
# completed or close to have done so.
if self._thread is not None:
self._thread.join()
return self.get_results()

def join(self):
self._thread.join()

def is_alive(self):
return self._thread.is_alive()

def get_results(self):
response = self._storage.get('response')
if self._has_run is False:
raise ArcsecondError("Uploader hasn't started. Results can't be retrieved.")
response = self._storage.get('response', None)
if isinstance(response, dict):
# Responses of standard JSON payload requests are dict
return response
Expand All @@ -65,4 +69,4 @@ def get_results(self):
else:
return None, response.text
else:
return None, self._storage.get('error')
return None, self._storage.get('error', None)

0 comments on commit 46f0445

Please sign in to comment.