How can I get the name of the stream, knowing the identifier of the stream?

I am working on a multi-threaded trace script, I am using the following code example to get the stream name, is there a better way to get the stream name from the stream id?

for threadId, stack in sys._current_frames().items(): tname = "None" for mthread in threading.enumerate(): if mthread.ident == threadId: tname = mthread.name 
+4
source share
1 answer

There is no threading in the public interface. Internally, threading supports exactly what you want you to write (at your own risk)

 def thread_for_ident(ident): return threading._active.get(ident) 

which will return None if such a stream does not exist. I do not think that you decision is actually too bad, until there are so many threads.

+3
source

Source: https://habr.com/ru/post/1480495/


All Articles