Hacker Timesnew | past | comments | ask | show | jobs | submitlogin
Why Python needs to be paused during profiling – but Ruby doesn't always (benfrederickson.com)
86 points by todsacerdoti on Nov 10, 2021 | hide | past | favorite | 12 comments


Without nonblocking mode in py-spy (which is amazing, by the way!), I had a case where some compiled code froze until I manually sent a SIGCONT.


Sorry about leaving your program suspended - I believe that was because of a bug that should be fixed now https://github.com/benfred/py-spy/issues/390 =(


Well look at that! I guess I'll try it again with a newer version when I get a chance, thanks!


Slight tagent but do you and many others here appear mere hours after their project is mentioned? Pure luck or a large percentage of HN users are querying the api to see who mentions their projects?


Interesting I’ve had this happen with strace and/or gdb before when hitting control-c a few times.


thank you so much! it wasn't a big deal (if you remembered to check after using py-spy, granted). i'd take py-spy with this bug vs not having py-spy at all any day :)


i've seen this multiple times, happens especially when detaching py-spy. have to be very careful to check if the process isn't stopped when debugging in prod ^_^


Does anyone know why Python chose linked list for its frames vs an array like Ruby? I imagine both choices have their own advantages and disadvantages.


No definitive answer, but educated guess: I'm not sure how things are in Ruby, but in Python frame object lifetime does not correspond to the C stack implementing the interpreter. If your code throws an exception, frames are returned as part of the public API of the exception object, and can thus indefinitely outlive the associated function execution.

You could still implement an array-oriented frame stack in Python, but I think that would mean exceptions become more expensive, as it means making a complete copy of the array any time an exception was thrown, even if the user never makes use of it.


It would be trivial to change from a linked list to an allocated vector if it were not for exposed APIs. In fact it would most likely be more efficient.


Interesting. Wasn't the selling point of Stackless Python that it did not use the C stack (as done by CPython) as the Python stack?


Most likely because it was easier. It's definitely not a good choice but unfortunately `PyFrame_GetBack(PyFrameObject *)` exists as an API which makes it tricky now to switch to something else as it must be possible to discover the previous frame from a frame. It's even exposed to userspace with `frameobject.f_back`.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: