pythonpython-multithreadinginfinite-loop

Outputting variable from one thread to other


I have a thread that has an infinite loop running, updating a variable constantly. How can I access the live value of that variable in an another thread/outside of the thread (without being in an infinite loop)?


Solution

  • the best way to do it is to use global variables. But, you need to be aware of the lock conditions when threads are reading and writing to one variable at once.

    There is a good manual for example.