What is and is not automatically streaming in Python Threading?

It’s not easy for me to wrap my head around Python threading, especially since the documentation will tell you explicitly about RTFS at some points, rather than kindly including the relevant information. I admit that I do not know how to read the streaming module. I saw a lot of simple examples, but they all use global variables, which is offensive and makes me wonder if anyone knows when and where they should use them, and not just conveniently.

In particular, I would like to know:

  • B threading.Thread(target=x), xgeneral or closed? Each thread has its own stack or all threads use the same context at the same time?
  • What is the preferred way to pass changed variables to threads? The immutable, obviously, go through the Thread(args=[],kwargs={})fact that they cover all the examples. If it's global, I'll have to hold my nose and use it, but it seems like there should be a better way. I suppose that I could wrap everything in the class and just pass the instance, but it would be nice to point to regular variables as well.
  • When do I need threading.local()? In the xabove?
  • Do I need to subclass Thread to update data, as many examples show?

I got used to Win32 and pthreads threads, where I explicitly stated in documents what is and is not used for different applications of threads. These are pretty low level, and I would like to avoid _thread, if possible, be pythonic.

, , OpenMP-, - . globals locks, .

+4
1

threading.Thread(target = x) x ?

. x.

, ( ). x , x "private" .

? Thread ?

target , , . , , , ( , , ).

threading.Thread. , / , __init__, ( run).

threading.local()?

, , , .

_thread, , pythonic

, .

+3

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


All Articles