Skip to content

Commit a43c92f

Browse files
committed
Merge fix
1 parent c2308cc commit a43c92f

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ mixpanel==4.8.3
1717
pydantic>=1.10.4
1818
setuptools>=57.4.0
1919
email-validator>=1.0.3
20-
nest-asyncio==1.5.4
2120
jsonschema==3.2.0
2221
pandas>=1.1.4
2322
aiofiles==0.8.0

src/superannotate/lib/core/usecases/annotations.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import re
1010
import time
1111
import traceback
12+
import typing
1213
from dataclasses import dataclass
1314
from datetime import datetime
1415
from itertools import islice
@@ -57,6 +58,20 @@
5758
URI_THRESHOLD = 4 * 1024 - 120
5859

5960

61+
def run_async(f):
62+
from threading import Thread
63+
64+
response = [None]
65+
66+
def foo(f: typing.Callable, res):
67+
res[0] = asyncio.run(f) # noqa
68+
69+
thread = Thread(target=foo, args=(f, response))
70+
thread.start()
71+
thread.join()
72+
return response[0]
73+
74+
6075
@dataclass
6176
class Report:
6277
failed_annotations: list
@@ -390,7 +405,7 @@ def execute(self):
390405
len(items_to_upload), description="Uploading Annotations"
391406
)
392407
try:
393-
asyncio.run(self.run_workers(items_to_upload))
408+
run_async(self.run_workers(items_to_upload))
394409
except Exception:
395410
logger.debug(traceback.format_exc())
396411
self._response.errors = AppException("Can't upload annotations.")
@@ -735,7 +750,7 @@ def execute(self):
735750
except KeyError:
736751
missing_annotations.append(name)
737752
try:
738-
asyncio.run(self.run_workers(items_to_upload))
753+
run_async(self.run_workers(items_to_upload))
739754
except Exception as e:
740755
logger.debug(e)
741756
self._response.errors = AppException("Can't upload annotations.")
@@ -933,7 +948,7 @@ def execute(self):
933948
size = annotation_file.tell()
934949
annotation_file.seek(0)
935950
if size > BIG_FILE_THRESHOLD:
936-
uploaded = asyncio.run(
951+
uploaded = run_async(
937952
self._service_provider.annotations.upload_big_annotation(
938953
project=self._project,
939954
folder=self._folder,
@@ -945,7 +960,7 @@ def execute(self):
945960
if not uploaded:
946961
self._response.errors = constants.INVALID_JSON_MESSAGE
947962
else:
948-
response = asyncio.run(
963+
response = run_async(
949964
self._service_provider.annotations.upload_small_annotations(
950965
project=self._project,
951966
folder=self._folder,
@@ -1518,14 +1533,15 @@ def execute(self):
15181533
sort_response = self._service_provider.annotations.get_upload_chunks(
15191534
project=self._project,
15201535
item_ids=list(id_item_map),
1536+
15211537
)
15221538
large_item_ids = set(map(itemgetter("id"), sort_response["large"]))
15231539
large_items: List[BaseItemEntity] = list(
15241540
filter(lambda item: item.id in large_item_ids, items)
15251541
)
15261542
small_items: List[List[dict]] = sort_response["small"]
15271543
try:
1528-
annotations = asyncio.run(self.run_workers(large_items, small_items))
1544+
annotations = run_async(self.run_workers(large_items, small_items))
15291545
except Exception as e:
15301546
logger.error(e)
15311547
self._response.errors = AppException("Can't get annotations.")
@@ -1731,7 +1747,7 @@ def execute(self):
17311747
)
17321748
small_items: List[List[dict]] = sort_response["small"]
17331749
try:
1734-
asyncio.run(
1750+
run_async(
17351751
self.run_workers(
17361752
large_items, small_items, folder, new_export_path
17371753
)

0 commit comments

Comments
 (0)