forked from supervisely/supervisely
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgrade to Python 3.8 + Applications pre-release
[agent] support of applictions, no_proxy env, pull_policy reimplemented [SDK] api to upload videos api [SDK] advanced api to work with object tags (work in progress) [SDK/annotation] stats methods [SDK/api] ignore_task_id (internal usage) + print retries [SDK/api/file_api] api to work with files [SDK/geometries] transformations (to_polygon, to_bitmap, ...) [SDK/api/project + dataset] add reference_image_url [dockerimages] upgrade all images, will be released later [images] alpha channel support [sdk/label] fix crop to keep ids [new images import] not released [annotation] add id field [nn] new default batch sizes and more ...
- Loading branch information
1 parent
d1915e3
commit a24e936
Showing
104 changed files
with
2,701 additions
and
488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
agent:6.0.24 | ||
agent:6.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# coding: utf-8 | ||
|
||
import concurrent.futures | ||
import json | ||
import base64 | ||
|
||
import supervisely_lib as sly | ||
|
||
from worker import constants | ||
from worker.task_logged import TaskLogged | ||
|
||
|
||
class AppFileStreamer(TaskLogged): | ||
def __init__(self): | ||
super().__init__({'task_id': 'file_streamer'}) | ||
self.thread_pool = None | ||
|
||
def init_logger(self): | ||
super().init_logger() | ||
sly.change_formatters_default_values(self.logger, 'worker', 'file_streamer') | ||
|
||
def init_additional(self): | ||
super().init_additional() | ||
self.thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=10) | ||
|
||
def task_main_func(self): | ||
try: | ||
self.logger.info('FILE_STREAMER_INITIALIZED') | ||
for gen_event in self.api.get_endless_stream('GetGeneralEventsStream', | ||
sly.api_proto.GeneralEvent, sly.api_proto.Empty()): | ||
event_obj = { | ||
'request_id': gen_event.request_id, | ||
'data': json.loads(gen_event.data.decode('utf-8')), | ||
} | ||
self.logger.debug('GET_STREAM_FILE_CALL', extra=event_obj) | ||
self.thread_pool.submit(sly.function_wrapper_nofail, self.stream_file, event_obj) | ||
|
||
except Exception as e: | ||
self.logger.critical('FILE_STREAMER_CRASHED', exc_info=True, extra={ | ||
'event_type': sly.EventType.TASK_CRASHED, | ||
'exc_str': str(e), | ||
}) | ||
|
||
def stream_file(self, event_obj): | ||
# @TODO: path to basee64: hash = base64.b64encode(path.encode("utf-8")).decode("utf-8") | ||
data_hash = event_obj['data']['hash'] | ||
suffix = event_obj['data']['ext'] | ||
st_path = base64.b64decode(data_hash).decode("utf-8") | ||
|
||
#st_path = self.data_mgr.storage.images.check_storage_object(data_hash=event_obj['data']['hash'], | ||
# suffix=event_obj['data']['ext']) | ||
|
||
if st_path is None: | ||
def chunk_generator(): | ||
yield sly.api_proto.Chunk(error='STREAMER_FILE_NOT_FOUND') | ||
|
||
try: | ||
self.api.put_stream_with_data('SendGeneralEventData', sly.api_proto.Empty, chunk_generator(), | ||
addit_headers={'x-request-id': event_obj['request_id']}) | ||
except: | ||
pass | ||
|
||
return | ||
|
||
file_size = sly.fs.get_file_size(st_path) | ||
|
||
def chunk_generator(): | ||
with open(st_path, 'rb') as file_: | ||
for chunk_start, chunk_size in sly.ChunkSplitter(file_size, constants.NETW_CHUNK_SIZE()): | ||
bytes_chunk = file_.read(chunk_size) | ||
yield sly.api_proto.Chunk(buffer=bytes_chunk, total_size=file_size) | ||
|
||
self.api.put_stream_with_data('SendGeneralEventData', sly.api_proto.Empty, chunk_generator(), | ||
addit_headers={'x-request-id': event_obj['request_id']}) | ||
self.logger.debug("FILE_STREAMED", extra=event_obj) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.