I’m trying to implement AsyncIO
with Kivy.
I have MainWidget(BoxLayout)
class which possesses all functionality of the code for our case it is communicating with Android API to fetch I/O network data e.g., scanning for unpaired Bluetooth devices. Please don’t ask why it is done inside MainWidget
and not our App Class – wasn’t my doing.
class MainWidgetr(BoxLayout):
async def scan_bluetooth(self):
# [...] bluetooth logic here
# how do I get this to run asynchronously when button is pressed?
Then, we have ClassApp(App)
which consists of the function to run the app asynchronously
. This is my first time working with asyncIO
and I heard that it is a modern approach than Threading
and if-not perfect for I/O bound problems though I also just want to test this vs Threading
later.
Inside our ClassApp(App)
class we have a app_func
function as per Kivy AsyncIO advanced example.
def app_func(self):
async def run_wrapper():
await self.async_run(async_lib='asyncio')
return asyncio.gather(run_wrapper())
Issue is, I tried looking on the internet on how to; when I press button Start Scan
I want asynchronously
carry out the scan. However, how do I go about adding it into the app_func
or the Event Loop so that on button trigger the function is done asynchronously?
NOTE: My understanding of asynchronous programming is very basic so I hope my explanation is enough.
Thanks.
5