Skip to content

Commit

Permalink
issue-1299 set empty async response to None
Browse files Browse the repository at this point in the history
  • Loading branch information
kykrueger committed Oct 19, 2023
1 parent 72eb3c8 commit 9b79923
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tableauserverclient/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# For when a datasource is over 64MB, break it into 5MB(standard chunk size) chunks
CHUNK_SIZE_MB = 5 * 10 # 5MB felt too slow, upped it to 50

DELAY_SLEEP_SECONDS = 10
DELAY_SLEEP_SECONDS = 0.1

# The maximum size of a file that can be published in a single request is 64MB
FILESIZE_LIMIT_MB = 64
19 changes: 9 additions & 10 deletions tableauserverclient/server/endpoint/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def set_user_agent(parameters):
# return explicitly for testing only
return parameters

def _blocking_request(self, method, url, parameters={}) -> Optional["Response"]:
def _blocking_request(self, method, url, parameters={}) -> Optional[Union["Response", Exception]]:
self.async_response = None
response = None
logger.debug("[{}] Begin blocking request to {}".format(datetime.timestamp(), url))
Expand All @@ -96,32 +96,31 @@ def _blocking_request(self, method, url, parameters={}) -> Optional["Response"]:

def send_request_while_show_progress_threaded(
self, method, url, parameters={}, request_timeout=0
) -> Optional["Response"]:
) -> Optional[Union["Response", Exception]]:
try:
request_thread = Thread(target=self._blocking_request, args=(method, url, parameters))
request_thread.async_response = -1 # type:ignore # this is an invented attribute for thread comms
request_thread.start()
except Exception as e:
logger.debug("Error starting server request on separate thread: {}".format(e))
return None
seconds = 0
seconds = 0.05
minutes = 0
sleep(1)
if self.async_response != -1:
sleep(seconds)
if self.async_response is not None:
# a quick return for any immediate responses
return self.async_response
while self.async_response == -1 and (request_timeout == 0 or seconds < request_timeout):
while (self.async_response is None) and (request_timeout == 0 or seconds < request_timeout):
self.log_wait_time_then_sleep(minutes, seconds, url)
seconds = seconds + DELAY_SLEEP_SECONDS
if seconds >= 60:
seconds = 0
minutes = minutes + 1
seconds -= 60
minutes += 1
return self.async_response

def log_wait_time_then_sleep(self, minutes, seconds, url):
logger.debug("{} Waiting....".format(datetime.timestamp()))
if seconds >= 60: # detailed log message ~every minute
if minutes % 5 == 0:
if minutes % 1 == 0:
logger.info(
"[{}] Waiting ({} minutes so far) for request to {}".format(datetime.timestamp(), minutes, url)
)
Expand Down

0 comments on commit 9b79923

Please sign in to comment.