MCPcopy
hub / github.com/alibaba/EasyCV / write

Method write

easycv/file/file_io.py:759–783  ·  view source on GitHub ↗
(self, content)

Source from the content-addressed store, hash-verified

757 self.buffer = StringIO()
758
759 def write(self, content):
760 # without a "with" statement, the content is written immediately without buffer
761 # when writing a large batch of contents at a time, this will be quite slow
762 import oss2
763 buffer = self.buffer.getvalue()
764 if buffer:
765 content = buffer + content
766 self.buffer.close()
767 self.buffer = StringIO()
768 try:
769 result = self.bucket.append_object(self.path, self.position,
770 content)
771 self.position = result.next_position
772 except oss2.exceptions.PositionNotEqualToLength:
773 raise RuntimeError(
774 f'Race condition detected. It usually means multiple programs were writing to the same file'
775 f'{OSS_PREFIX}{self.bucket.bucket_name}/{self.path} (Error 409: PositionNotEqualToLength)'
776 )
777 except (oss2.exceptions.RequestError,
778 oss2.exceptions.ServerError) as e:
779 self.buffer.write(content)
780 logging.error(
781 str(e) +
782 f'when writing to {OSS_PREFIX}{self.bucket.bucket_name}/{self.path}. Content buffered.'
783 )
784
785 def flush(self, retry=0):
786 import oss2

Callers 15

flushMethod · 0.95
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
write_raw_labelFunction · 0.80
generate_train_valFunction · 0.80
to_ms_configFunction · 0.80
_startMethod · 0.80

Calls 2

RuntimeErrorClass · 0.90
closeMethod · 0.80

Tested by 10

_startMethod · 0.64
test_openMethod · 0.64
test_moveMethod · 0.64
test_openMethod · 0.64
test_moveMethod · 0.64
_base_predictMethod · 0.64
_base_pruneMethod · 0.64
_replace_configMethod · 0.64
test_single_cpuMethod · 0.64