Closed EricLin89 closed 1 year ago
Cannot reproduce.
$ ls
test.py
$ cat test.py
import time
message = ""
while True:
message += "x"
time.sleep(0.1)
$ python3.7 -m venv venv
$ . venv/bin/activate
(venv) $ python test.py &
[1] 27554
(venv) $ pip install memray
...
Installing collected packages: typing-extensions, pygments, mdurl, MarkupSafe, markdown-it-py, jinja2, rich, memray
Successfully installed MarkupSafe-2.1.3 jinja2-3.1.2 markdown-it-py-2.2.0 mdurl-0.1.2 memray-1.9.1 pygments-2.16.1 rich-13.5.2 typing-extensions-4.7.1
(venv) $ memray attach 27554
Memray WARNING: Correcting symbol for aligned_alloc from 0x7f724c9e57f0 to 0x7f724e18c000
(successfully shows a TUI, then when I press `q` I get:)
Failed to write output, deactivating tracking
(venv) $
Are you sure that the environment that you installed Memray into was the environment that the script you were trying to attach to was running with? Things ought to work just fine as long as you install Memray into a directory that's on the sys.path
of the process you're attaching to, and in my testing they do.
Thanks. I checked again and found the problem.
In my environment, memray is installed under /usr/local/lib64/python3.7/site-packages
by default. The directory does not exist before memray is installed. So the processes started before memray is installed does not have this path in sys.path
. Installing memray into existing sys.path
should solve the problem.
Is there an existing issue for this?
Current Behavior
using memray attach command to attach to a running process, the command reports "No module named 'memray'" error. This happens when memray is installed after the process is started. After I restart the process and use
memray attach
again, the command works as expected.Expected Behavior
memray attach works on processes started before memray is installed.
Steps To Reproduce
memray attach $pid
to the processMemray Version
1.9.0
Python Version
3.7
Operating System
Linux
Anything else?
No response