Skip to content

Commit

Permalink
Small protection against fetching results too early
Browse files Browse the repository at this point in the history
Signed-off-by: Cédric Foellmi <cedric@onekiloparsec.dev>
  • Loading branch information
onekiloparsec committed May 6, 2020
1 parent c42d4ee commit 3db06fd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 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 @@ -54,7 +56,9 @@ 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 @@ -64,4 +68,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 3db06fd

Please sign in to comment.