Skip to content

Locking ContextManager and websocket patching #172

Answered by fscherf
mwx23 asked this question in Q&A
Discussion options

You must be logged in to vote

@mwx23 Excellent question! No. Locking has nothing to do with sending updates over the websocket, it's a mechanism to avoid race conditions between threads.

Let's say we have a view with a counter that gets increased once a second, and there is a button to decrease the counter. The counter may be never lower than one (code is not tested).

class CounterView(LonaView):
    def handle_button_click(self, input_event):
        with self.html.lock:
            current_value = int(self.html[0].get_text())
            value = current_value - 1

            if value < 0:
                value = 0

            self.html[0].set_text(value)

    def handle_request(self, request):
        self.html = H…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mwx23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants