STINNER Victor <vstin...@python.org> added the comment:

> 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.

https://docs.python.org/dev/library/asyncio-eventloop.html#asyncio.loop.call_soon_threadsafe

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue35370>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to