sys.settrace for all threads

Martin v. Loewis martin at
Fri Oct 4 23:52:57 CEST 2002

richie at (Richie Hindle) writes:

> Is there a cleaner and more future-proof way of doing this?

No. Your approach won't work very well, either, since threads can come
out nowhere: A C module may create threads, and just temporarily enter
Python from the thread.

If you want to hook into all threads, you need to hook into
PyThreadState_New and friends.

If you want a future-proof way, I recommend to create a
per-interpreter state global, and hook into all places that use the
trace function. You might want to try writing a PEP to generalize this


More information about the Python-list mailing list