Attempt to catch MemoryError if possible

This commit is contained in:
Matt Martz 2017-10-16 09:26:47 -05:00
parent 16054cc3bc
commit 3cb44f5630
1 changed files with 11 additions and 5 deletions

View File

@ -743,11 +743,17 @@ class HTTPUploaderData(object):
chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
multiplier = int(round(int(self.length) / 36.0)) multiplier = int(round(int(self.length) / 36.0))
IO = BytesIO or StringIO IO = BytesIO or StringIO
try:
self._data = IO( self._data = IO(
('content1=%s' % ('content1=%s' %
(chars * multiplier)[0:int(self.length) - 9] (chars * multiplier)[0:int(self.length) - 9]
).encode() ).encode()
) )
except MemoryError:
raise SpeedtestCLIError(
'Insufficient memory to pre-allocate upload data. Please '
'use --no-pre-allocate'
)
@property @property
def data(self): def data(self):