tools to help writing async python codes
%%time
@async_wrap
def aSlowFunc(input_:str):
time.sleep(2)
return input_
## async func execute
import nest_asyncio, time
nest_asyncio.apply()
import time
async def runASlowFunc(input_):
return await aSlowFunc(input_)
async def runLoop():
rtup = (runASlowFunc(i) for i in range (10))
r = await asyncio.gather(*rtup)
return r
asyncio.run(runLoop())
async def main():
await asyncio.sleep(1)
print('hello')
asyncio.run(main())
%%time
import time
asyncMap(lambda x: (x+1, time.sleep(1))[0] , range(100), threads = 100)[:10]
def aSlowFunc(x):
time.sleep(1)
return x
%%time
asyncMap(aSlowFunc, range(100))[:10]
input_ = list(zip(range(10), range(1,11)))
print(input_)
asyncMap(lambda x: (lambda x,y: x+y )(x[0],x[1]), input_)
%%time
import nest_asyncio
nest_asyncio.apply()
asyncAwaitMap(aSlowFunc, range(100))[:10]
input_ = list(zip(range(10), range(1,11)))
print(input_)
asyncAwaitMap(lambda x: (lambda x,y: x+y )(x[0],x[1]), input_)
%%time
def aSlowFunc(x):
time.sleep(1)
return x
list(asyncThreadMap(aSlowFunc, range(100)))[:10]
%%time
def aSlowFunc(x):
time.sleep(1)
return x
list(asyncProcessMap(aSlowFunc, range(100)))[:10]