We are currently working on adding tracing support to Anaconda, the Fedora/Red Hat Enterprise Linux installer and we have encountered some pretty strange behavior of the trace module. Anaconda (or to be concrete the Blivet storage library used by Anaconda) uses the pyblock module, but just importing it crashes the trace module with a strange exception.
It can be reproduced like this:
0. install pyblock (on Fedora is is provided by the python-pyblock package)
1. write some python code that imports the "block" module provided by pyblock
echo "import block" > pyblock_trace.py
2. try to trace the code
python -m trace -t pyblock_trace.py
The trace module starts tracing but after a few seconds it crashes with the following traceback:
Traceback (most recent call last):
File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/lib64/python2.7/trace.py", line 830, in <module>
main()
File "/usr/lib64/python2.7/trace.py", line 818, in main
t.runctx(code, globs, globs)
File "/usr/lib64/python2.7/trace.py", line 513, in runctx
exec cmd in globals, locals
File "pyblock_trace.py", line 1, in <module>
import block
File "/usr/lib64/python2.7/site-packages/block/__init__.py", line 47, in <module>
import dmraid
File "<string>", line 1, in <module>
File "/usr/lib64/python2.7/trace.py", line 609, in globaltrace_lt
filename = frame.f_globals.get('__file__', None)
AttributeError: 'module' object has no attribute 'get'
The dmraid module is written in C and we have looked though its source[1] code but have found nothing extraordinary. Most importantly there is no code touching the globals, but it still fails.
When looking what actually is in frame.f_globals we found that in all successful calls it has the globals dictionary but for the dmraid module it for some reason contains the module instance instead. Module instance is not a dictionary, so it doesn't have the get method and this leads to the exception above.
This is not the only C module we use, but this is the only one that triggers the crash in trace.
Additional information
Python version: 2.7.5
architecture: X86_64
OS: Fedora 20
[1] https://git.fedorahosted.org/cgit/pyblock.git/tree/dmraid.c
|