python - How to mix asyncio code in with blocking code? -


this question has answer here:

how go mixing code/statements/functions want run outside main thread mixed in code strickly runs on main thread.

in mobile world have tools rxjava, asynctask, runnables, rxswift , stuff drop in lines run in background , not bother fluidness of main code.

so how utilize asyncio lib , intermingle non blocking code blocking code?

   def mumbojumbocode():         regularstuff = dosomeregularstuff()         illgetitlater = sendsomestufftoawebsocketinthebackground(regularstuff)         moreregularstuff = dosomemoreregularstuff()         idontcarewhatitreturns = sendamessageoverthewire(illgetitlater)         if (moreregularstuff => regularstuff):               triggeralambdasomewhereinthecloud(moreregularstuff) 

you can simulate blocking code while in async mode, not other way around.

so, if program system in async mode, can set flag in event handler, , wait flag change in polling loop, changing mode sync mode. if want asynchronously, can change behavior of handler.


Comments

Popular posts from this blog

how to do line continuation in perl debugger for entering raw multi-line text (EOT)? -

javascript - Create websocket without connecting -

android - Linear layout children not scrolling -