Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bad Marshal error -- runsnake

I ran cProfile on a python 3 script, worked nicely, then tried to visualize it using runsnake. Howvever, I got an empty screen and the error 'bad marshal data'.

I removed .pyc file but that did not work either.

The code I used to install runsnake was:

    sudo apt-get install python-profiler python-wxgtk2.8 python-setuptoolD
    sudo easy-install installSquareMap RunSnakeRun

I am using UBUNTU.

Many thanks.

note: I should add I installed everything while py3k was activated

like image 968
kat Avatar asked Sep 23 '14 16:09

kat


1 Answers

TL;DR: This error occurs when profiling in Python 2.x and viewing the profile in Python 3.x or vice versa.

I had the same problem. As far as I can tell, the RunSnakeRun package has not been ported to Python3. At least, I could pip it to python2 but not to python3 (SyntaxError). Further, I think the output format of cProfile is not compatible between python 2/3. I did not take the time to find an definitive confirmation of this, but in the doc of cProfile class pstats.Stats(*filenames, stream=sys.stdout), they do say "The file selected by the above constructor must have been created by the corresponding version of profile or cProfile. To be specific, there is no file compatibility guaranteed with future versions of this profiler, and there is no compatibility with files produced by other profilers.". This seems to be the origin of your problem. For e.g., I made a profile output from python3

import cProfile
cProfile.run('some code to profile', 'restats')

and tried to open it in RunSnakeRun and got the same marhsal error you got. Further, if I do

import pstats
p = pstats.Stats('restats')
p.strip_dirs().sort_stats(-1).print_stats()

in python3, it works like a charm. If I do it in python2, it gives the marshal error. Now, RunSnakeRun is executed in python2 (unless you found some way to make it run in python3). So, my guess is that you have performed your profiling in python3 and are using tools relying on python2 to analyze them, which tools are expecting the output to be compatible with python2.

The RunSnakeRun project seems to be inactive for a while now (copyright on the home page is 2005-2011) and there is no indication that it will be ported to python3.... Maybe considering alternative visualization tool might be the best way to go for you if you want to develop in Python3. pyprof2calltree in combination with KCachegrind worked fine for me in Linux. It can provide a similar visual view of the profiling output as you would get from RunSnakeRun.

like image 123
Christian O'Reilly Avatar answered Oct 04 '22 14:10

Christian O'Reilly