pythonprofilers / memory_profiler

Monitor Memory usage of Python code
http://pypi.python.org/pypi/memory_profiler
Other
4.37k stars 378 forks source link

memory_profiler does not print anything #228

Open rakesh-k opened 5 years ago

rakesh-k commented 5 years ago

Guys - I know it is fixed for python3 but I am still getting this error. I reinstalled the profiler but the error is persistent.

MBP:python$ sudo -H pip3 install -U memory_profiler
Password:
Collecting memory_profiler
  Downloading https://files.pythonhosted.org/packages/9f/fe/1fca7273dd111108f204a686b12a12b6422d405fe4614087aa7d5a66ea87/memory_profiler-0.55.0.tar.gz (40kB)
    100% |████████████████████████████████| 40kB 2.5MB/s 
Requirement already satisfied, skipping upgrade: psutil in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from memory_profiler) (5.6.1)
Installing collected packages: memory-profiler
  Running setup.py install for memory-profiler ... done
Successfully installed memory-profiler-0.55.0

MBP:python$ python -m memory_profiler foo.py 
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/memory_profiler.py:649: UserWarning: Could not extract a code object for the object <class '__main__.Foobar'>
  % func)

And here is the code I am trying to profile:

from memory_profiler import profile

@profile
class Foobar(object):
    def __init__(self, x):
        self.x = x

if __name__ == '__main__':
    f = [Foobar(i) for i in range(1000000)]
mghmgh1281375 commented 4 years ago

Try this.

from memory_profiler import profile
class Foobar(object):
    @profile
    def __init__(self, x):
        self.x = x