This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients fabioz, vstinner
Date 2020-03-16.18:36:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> I.e.: something as adding a thread_id to sys.settrace -- sys.settrace(trace_func, thread_id=None).

What is the use case for this feature?

It seems quite complicated to implement the thread_id for sys.settrace(trace_func, thread_id=None).

Currently, there is no way for a thread to execute code directly in another thread. In asyncio, it has to through call_soon_threadsafe() which queues the function calls and the function is called "later" and the caller doesn't get the result.

sys.setprofile() and sys.settrace() use the current Python thread state (tstate). The threading.enumerate() function returns threading.Thread instances, but it's not currently possible to get the Python thread state (C structure PyThreadState) from a Python threading.Thread object.

At the C level, Python doesn't maintain a list of thread. There is only threading.enumerate() which is implemented in Python.

PyDev.Debugger seems to use the C API. Can it continue to use the C API?

Note: There is threading.setprofile() and threading.settrace() which set a profile/trace function when *new* threads are spawned.
Date User Action Args
2020-03-16 18:36:15vstinnersetrecipients: + vstinner, fabioz
2020-03-16 18:36:15vstinnersetmessageid: <>
2020-03-16 18:36:15vstinnerlinkissue35370 messages
2020-03-16 18:36:15vstinnercreate