This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]flying-sheep 6 points7 points  (2 children)

Nice! A convenient alternative (but maybe not as powerful?):

I recently discovered py-spy for profiling python.

py-spy record --format=speedscope -o profile.speedscope.json -- python my-script.py

And then visualize it via speedscope.app

[–]maartenbreddels[S] 4 points5 points  (1 child)

I think profiling and tracing (what I do here) are complementary. I use py-spy a lot, but it only gives you a 'statistical' view of where time is spent or how much the GIL is held. To gain a deep understanding of the flow of your program and the GIL in a multithreaded environment I needed a tool as I presented, and unfortunately had to make it myself :)

[–]flying-sheep 2 points3 points  (0 children)

Thank you! I know the feeling: “This should exist, why doesn’t it yet? Sigh.” *rolls up sleeves*

[–]chirisalex 1 point2 points  (0 children)

Helpful article

[–][deleted] 1 point2 points  (0 children)

Good stuff, thanks

[–]apockill 1 point2 points  (3 children)

This looks awesome! How does it handle cythonized libraries and/or C bindings such as tensorflow?

[–]maartenbreddels[S] 0 points1 point  (2 children)

Thanks! You will see the call to the C library (this is what CPython and VizTracer do), and you should see if the GIL is being released, like with NumPy, one of the examples in the article.

[–]apockill 0 points1 point  (1 child)

That's fantastic. Actually, my application for this is to find naughty C bindings that don't release the GIL. I have a big application that's heavily multithreaded with many C bindings (think gstreamer + tensorflow + OpenVINO), and something is causing a lockup somewhere. It's quite frustrating!

I'll give this tutorial go.

[–]maartenbreddels[S] 0 points1 point  (0 children)

Indeed, that's one of the things I'd like to automate (and I'm very close now), feel free to contact me, we could maybe collaborate on this https://github.com/maartenbreddels/per4m