async def run_in_main(func_, *args, **kwargs): """ Run and return `func_(*args, **kwargs)` in the kernel's thread. Note that this should only be restricted to tkinter calls. """ # Note: the argument is `func_` to prevent name clashes in `kwargs`. # This can become a positional only parameter (introduced in Python # 3.8) once curio deprecates its usage in Python 3.6 and 3.7. async with spawn_thread(): return AWAIT(_call(func_, args, kwargs))
async def coro1(): results.append('coro1') async with spawn_thread(): # Calling an async_thread function from a thread context block should # work like a normal sync function call func1(threading.currentThread())
async def worker2(): async with spawn_thread(): AWAIT(evt.wait) results.append('worker2')
async def func(x, y): async with spawn_thread(): time.sleep(0.5) results.append(AWAIT(simple_coro(x, y)))
async def run_in_main(func_, *args, **kwargs): async with spawn_thread(): return AWAIT(_run_in_main_helper(func_, args, kwargs))