Fix race conditions in threaded code - #2
Conversation
…ix race condition on threaded code
… with highest # hits. This is the same behaviour used by `print_stats`
|
I made one more change in a5d0e54 to fix some behavior that was different compared to 3.5.x. |
Thanks for finding this! I wasn't sure whether 3.5.x was wrong or whether my version was wrong when I first encountered this, but now I know my version was wrong. |
Eager prof mod tempfile updates
kernprof.py
_restore
- Refactored from `_restore_list`
- New class methods `.sequence()`, `.mapping()`, and
`.instance_dict()` for restoring various objects
_remove()
New utility function for deleting files and directories
main()
"Developer mode" options (note: all of the below should be
considered implementational details)
- Refactored internal methods for printing messages and
diagnostics to use `line_profiler._diagnostics.log`
- Now outputting diagnostics regardless of verbosity level if
`line_profiler._diagnostics.DEBUG`
- Now keeping the temporary files if
`line_profiler._diagnostics.KEEP_TEMPDIRS`
- Now not executing any source file (setup, pre-imports,
profiled code) nor writing profile output if
`line_profiler._diagnostics.NO_EXEC`
Hi and thanks for your work on line-profiler. I realize this is a fork, but it looks like it will be merged in soon (pyutils#165) so I'm taking the chance to apply a fix here instead of on V3.x
Currently, line-profiler is inconsistent when used on threaded code. The lines of some functions do not show up in the output at all.
This stems from two problems:
enable_countmust be a thread-local variable, or different threads will step on each other toes. This was discovered in Enable tracing for all threads. rkern/line_profiler#10, but never merged, so I have re-implemented here_c_last_timemust be thread-local as it is used bydisable. I don't know enough Cython to implement this withthreading.local(), so instead I changed_c_last_timeto be a mapping between the thread id and the map of LastTime'sI'm not sure how much this will impact performance; I have not measured it. Please let me know if there is a better solution.
Finally, here's a simple test case to show the issue: