s4cmd
s4cmd copied to clipboard
Better error reporting when MemoryError reading a file
s4cmd 2.1.0 outputs an inscrutable error and stack trace when it gets a MemoryError trying to read a file in read_file_chunk().
The debug verbose output does not say anything about the MemoryError, I only see it below because I added a bunch of print
statements (starting with !
) and a try/except
handler in read_file_chunk().
Btw I was running in a container with only 200MB free, trying to write a 1GB file to an S3-compatible system. Hopefully s4cmd is not trying to load the entire file into memory?
# s4cmd --debug --verbose --endpoint-url http://backup66:8085 put 1G s3://mybucket/1G
(D)s4cmd.py:662 read S3 keys from $HOME/.s3cfg file
(D)s4cmd.py:128 >> put_handler(<s4cmd.CommandHandler object at 0x7f1d30cd9bd0>, ['put', '1G', 's3://mybucket/1G'])
!!!calling func
(D)s4cmd.py:128 >> validate(<s4cmd.CommandHandler object at 0x7f1d30cd9bd0>, 'cmd|local|s3', ['put', '1G', 's3://mybucket/1G'])
!!!calling func
!!!back from func
(D)s4cmd.py:132 << validate(<s4cmd.CommandHandler object at 0x7f1d30cd9bd0>, 'cmd|local|s3', ['put', '1G', 's3://mybucket/1G']): None
(D)s4cmd.py:128 >> put_files(<s4cmd.S3Handler object at 0x7f1d3390f6d0>, ['1G'], 's3://mybucket/1G')
!!!calling func
(D)s4cmd.py:128 >> put_single_file(<s4cmd.S3Handler object at 0x7f1d3390f6d0>, <s4cmd.ThreadPool object at 0x7f1d2ce9e2d0>, '1G', 's3://mybucket/1G')
!!!calling func
!!!back from func
(D)s4cmd.py:132 << put_single_file(<s4cmd.S3Handler object at 0x7f1d3390f6d0>, <s4cmd.ThreadPool object at 0x7f1d2ce9e2d0>, '1G', 's3://mybucket/1G'): None
(D)s4cmd.py:128 >> upload(<ThreadUtil(Thread-1, started daemon 139763283113728)>, '1G', 's3://mybucket/1G')
!!!calling func
(D)s4cmd.py:128 >> lookup(<ThreadUtil(Thread-1, started daemon 139763283113728)>, <s4cmd.S3URL instance at 0x7f1d2436f6c8>)
!!!calling func
(D)s4cmd.py:404 >> S3APICALL head_object(Bucket='mybucket', Key='1G')
!!!getattr () {'Bucket': 'mybucket', 'Key': '1G'}
!!!back from func
(D)s4cmd.py:132 << lookup(<ThreadUtil(Thread-1, started daemon 139763283113728)>, <s4cmd.S3URL instance at 0x7f1d2436f6c8>): None
(D)s4cmd.py:128 >> read_file_chunk(<ThreadUtil(Thread-1, started daemon 139763283113728)>, '1G', 0, 1073741824)
!!!calling func
!read_file_chunk 1G
!read_file_chunk 1G pos 0
!EXCEPTION: read_file_chunk 1G pos 0: <type 'exceptions.MemoryError'>
!!!fail: [Runtime Failure] Unable to read data from source: 1G
(E)s4cmd.py:185 [Runtime Failure] Unable to read data from source: 1G
Exception in thread Thread-1:ad(s)]
Traceback (most recent call last):
File "/usr/lib64/python2.7/threading.py", line 812, in __bootstrap_inner
self.run()
File "/usr/bin/s4cmd.py", line 530, in run
fail('[Runtime Failure] ', exc_info=e)
File "/usr/bin/s4cmd.py", line 192, in fail
raise RuntimeError(status)
RuntimeError: 1
!!!fail: [Thread Failure] Unable to read data from source: 1G
(E)s4cmd.py:185 [Thread Failure] Unable to read data from source: 1G
!!!fail: [Runtime Exception] 1
(E)s4cmd.py:185 [Runtime Exception] 1
(E)s4cmd.py:187 Traceback (most recent call last):
File "/usr/bin/s4cmd.py", line 1939, in main
CommandHandler(opt).run(args)
File "/usr/bin/s4cmd.py", line 1568, in run
CommandHandler.__dict__[cmd + '_handler'](self, args)
File "/usr/bin/s4cmd.py", line 130, in wrapper
ret = func(*args, **kargs)
File "/usr/bin/s4cmd.py", line 1666, in put_handler
self.s3handler().put_files(source, target)
File "/usr/bin/s4cmd.py", line 130, in wrapper
ret = func(*args, **kargs)
File "/usr/bin/s4cmd.py", line 825, in put_files
pool.join()
File "/usr/bin/s4cmd.py", line 598, in join
self.tasks.join()
File "/usr/bin/s4cmd.py", line 473, in join
fail('[Thread Failure] ', exc_info=self.exc_info)
File "/usr/bin/s4cmd.py", line 192, in fail
raise RuntimeError(status)
RuntimeError: 1