Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Orange/misc/server_embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from functools import partial
from json import JSONDecodeError
from os import getenv
from typing import Any, Callable, List, Optional
from typing import Any, Callable, List, Optional, Dict, Union

from AnyQt.QtCore import QSettings
from httpx import AsyncClient, NetworkError, ReadTimeout, Response
Expand Down Expand Up @@ -306,7 +306,7 @@ async def _send_to_server(
queue.task_done()

async def _send_request(
self, client: AsyncClient, data: bytes, url: str
self, client: AsyncClient, data: Union[bytes, Dict], url: str
) -> Optional[List[float]]:
"""
This function sends a single request to the server.
Expand All @@ -331,7 +331,9 @@ async def _send_request(
"Content-Length": str(len(data)),
}
try:
response = await client.post(url, headers=headers, data=data)
# bytes are sent as content parameter and dictionary as data
kwargs = dict(content=data) if isinstance(data, bytes) else dict(data=data)
response = await client.post(url, headers=headers, **kwargs)
except ReadTimeout as ex:
log.debug("Read timeout", exc_info=True)
# it happens when server do not respond in time defined by timeout
Expand Down
3 changes: 2 additions & 1 deletion Orange/misc/tests/test_server_embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ def __init__(self, content):
def make_dummy_post(response):
@staticmethod
# pylint: disable=unused-argument
async def dummy_post(url, headers, data):
async def dummy_post(url, headers, content=None, data=None):
# when sleeping some workers to still compute while other are done
# it causes that not all embeddings are computed if we do not wait all
# workers to finish
assert (content is None) ^ (data is None)
await asyncio.sleep(random() / 10)
return DummyResponse(content=response)

Expand Down