def initial_number_adder(first_number_ever):
# takes an integer from user and adds 1
added_number = first_number_ever + 1
return added_number
async def repeated_number_adder(old_result):
while 1:
await asyncio.sleep(0.5)
if datetime.utcnow().second == 0 or datetime.utcnow().second == 30:
# takes the integer from the initial fxn, initially.
# takes the return value from itself on the 0th and 30th second of
# every minute, from then on.
# adds 1 as well.
new_result = old_result + 1
print(new_result)
return await new_result
async def other_cool_fxn():
print('extra function to make things more complex')
await asyncio.sleep(1)
async def main():
first_time = 0
# first result comes from user input. for example '1'
if first_time == 0:
first_result = initial_number_adder(1)
first_time = 1
second_result = await asyncio."""wait or gather?"""([repeated_number_adder(first_result)])
else:
# for all results after the first (and the second in this case. I'm hoping to clean this up and only run repeated_number_adder in the loop below.
all_subsequent_results = await asyncio."""wait/gather"""([repeated_number_adder("""result of return of repeated_number_adder"""),other_cool_fxn()])
# want something like a future here
loop = asyncio.get_event_loop()
loop.run_forever(main())
我希望运行一个初始(同步)函数(initial_number_adder),将它的返回传递给第二个异步函数(repeated_number_adder),然后在循环中运行该函数,将之前的返回值传递回自身,直到永远。
如果我能使这两个函数异步,并从任务列表中管理第一个函数的初始运行,那也会很好。这是我能想象的最好的开始方式(初始同步传递到异步循环)
我将使用aiohttp这样的设置来发出GET请求。一个函数最初返回一个大数据帧,第二个函数将异步追加一个新行,每15分钟进行一次计算,然后将数据帧和计算传递回自身。(只是想给好奇的人一个要点)
我很感激你的时间。如果有什么需要澄清的,请告诉我。在