f5-common-python icon indicating copy to clipboard operation
f5-common-python copied to clipboard

Use os.stat to get the size instead of reading the file in memory

Open sanathkumarbs opened this issue 6 years ago • 2 comments

Here the entire file is read, that's a very expensive operation and can easily hit a MemoryError.

https://github.com/F5Networks/f5-common-python/blob/0a16f6e10b29ba3bca1f1dabf9a6f8f5b438296c/f5/bigip/mixins.py#L272 To get the size, it might be better off to do:

import os
def _upload(self, fileinterface, **kwargs):
        size = os.stat(fileinterface.name).st_size

Wanted to bounce this idea before I created a PR. Let me know if this fix makes sense, will create a PR for this.

sanathkumarbs avatar Jul 12 '18 03:07 sanathkumarbs

@sanathkumarbs so long as it meets two requirements

  1. does it return the same value
  2. is it more performant (faster, less memory, etc)

if the above are true, send the PR.

caphrim007 avatar Jul 12 '18 03:07 caphrim007

@sanathkumarbs do you still need this if so can you send a PR ?

wojtek0806 avatar Aug 08 '18 09:08 wojtek0806