Skip to content

Commit

Permalink
Merge pull request #4994 from PrimozGodec/embedder-close-loop
Browse files Browse the repository at this point in the history
Server Embedder: remove warnings
  • Loading branch information
janezd committed Sep 21, 2020
2 parents 7f6c51d + f05e0af commit 7db86f1
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions Orange/misc/server_embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,13 @@ def embedd_data(

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
embeddings = asyncio.get_event_loop().run_until_complete(
self.embedd_batch(data, processed_callback)
)
try:
embeddings = asyncio.get_event_loop().run_until_complete(
self.embedd_batch(data, processed_callback)
)
except Exception:
loop.close()
raise

loop.close()
return embeddings
Expand Down Expand Up @@ -278,7 +282,7 @@ async def _send_request(
}
try:
response = await client.post(url, headers=headers, data=data)
except ReadTimeout:
except ReadTimeout as ex:
log.debug("Read timeout", exc_info=True)
# it happens when server do not respond in 60 seconds, in
# this case we return None and items will be resend later
Expand All @@ -289,9 +293,9 @@ async def _send_request(

if self.count_read_errors >= self.max_errors:
self.num_parallel_requests = 0 # for safety reasons
raise EmbeddingConnectionError
raise EmbeddingConnectionError from ex
return None
except (OSError, NetworkError):
except (OSError, NetworkError) as ex:
log.debug("Network error", exc_info=True)
# it happens when no connection and items cannot be sent to the
# server
Expand All @@ -301,11 +305,11 @@ async def _send_request(
self.count_connection_errors += 1
if self.count_connection_errors >= self.max_errors:
self.num_parallel_requests = 0 # for safety reasons
raise EmbeddingConnectionError
raise EmbeddingConnectionError from ex
return None
except Exception as e:
except Exception:
log.debug("Embedding error", exc_info=True)
raise e
raise
# we reset the counter at successful embedding
self.count_connection_errors = 0
self.count_read_errors = 0
Expand Down

0 comments on commit 7db86f1

Please sign in to comment.