Skip to content

noticing 'client_disconnect' event doesn't work while background task is running in the loop #2182

Answered by mturoci
Roz-floatic asked this question in Q&A
Discussion options

You must be logged in to vote

Okay, found the problem: The code above was creating an infinite loop on client initialization, which is fine as long as it uses asyncio.sleep that can suspend asyncio task execution. However, the problem was that the code never ran beyond the init function (due to infinite loop) thus could not mark the client initialization as done (q.client.initialized = True). This caused 2 problems:

  • Every user interaction (serve function call) spawned another update infinite loop - after 3 button clicks you would have 4 update loops doing the same update.
  • Since the code execution could not pass beyond init function, the run_on would never be called, thus neither routing, nor disconnected handler woul…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@mturoci
Comment options

@mturoci
Comment options

@Roz-floatic
Comment options

@mturoci
Comment options

Answer selected by Roz-floatic
@Roz-floatic
Comment options

@mturoci
Comment options

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