I'm wondering if there are any noticeable differences in performance between foo and bar:
class Interface:
def __init__(self, loop):
self.loop = loop
def foo(self, a, b):
return self.loop.run_until_complete(self.bar(a, b))
async def bar(self, a, b):
v1 = await do_async_thing1(a)
for i in range(whatever):
do_some_syncronous_work(i)
v2 = await do_async_thing2(b, v1)
return v2
async def call_foo_bar(loop):
a = 'squid'
b = 'ink'
interface = Interface(loop)
v_foo = interface.foo(a, b)
v_bar = await interface.bar(a, b)
But will the use of run_until_complete cause any practical, noticeable different to running my program?
(The reason I ask is I'm building an interface class which will accommodate decomposable "back-ends" some of which could be asynchronous. I'm hoping to use standard functions for the public (reusable) methods of the interface class so one API can be maintained for all code without messing up the use of asynchronous back-ends where an event-loop is available.)
Update: I didn't check the code properly and the first version was completely invalid, hence rewrite.
Foowill be executed synchronously whileBarnot. It might happen that the scheduling/distribution might be important, i.e. it might make a difference for final user.foo()is a blocking call. Alsorun_until_completecannot be called with already running event loop