Forum Archive

Asyncio does not work on the UI.

Lami

I want to run Asyncio from the UI button, but I get the error "there is no current event loop in thread 'dummy -1'" and cannot run it.
Is there a way to define a loop?
When I define a new loop using new and set, the UI freezes, so I predict that the UI also uses Asyncio and there is a conflict.
Is there any way to avoid it?

def button(sender):
         loop = asyncio.get_event_loop_policy().new_event_loop() #there is no current event loop in thread 'dummy -1
        gather = asyncio.gather(
            get_pass(target),
            get_pass(target),
            get_pass(target)
        )
        loop.run_until_complete(gather)

v=ui.load_view()
v['imageview1'].image=ui.Image('img/image.png')
v['imageview2'].image=ui.Image('img/image2.png')
v.present('sheet', hide_title_bar = True)

ccc

https://omz-software.com/pythonista/docs/ios/ui.html#ui.in_background

JonB

@Lami this is probably the definitive thread relating to threads and pythonista.

https://forum.omz-software.com/topic/4528/help-me-understand-pythonista-s-threads

You might consider setting up your thread pool executer outside of the button action.