'Python Websocket wait for variable change

I have a class that contains a websocket-client WebSocketApp, that is started in a thread. The websocket connection recieves messages and sets some class variables accordingly. One example is the login: A login message is sent, and after a while the on_message function recieves a successfull login message. When the function catches this message a self.logged_in variable is set to true. Currently I'm "waiting" for the variable to become true using a busy wait, which is obviously not very good.

while websocket.logged_in:
    pass

What I need is something like this

wait(websocket.logged_in=True, timeout=100)


Solution 1:[1]

Found a nice solution using synchronized Queues You just need to call queue.put(var) in your thread where the message arrives. In the main you call queue.get() which will wait until an element shows up in the queue. In my case I will probably use multiple queues with just one element for different responses that I'm going to get

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ivan