[edit] Python 3.6
There is a function:
def main(request):
do_something() // task takes some days
responce = {'status': 'started!'}
return responce
I need it to return a responce right after do_something() started and NOT waiting for do_something() to be finished. I have already tried this:
def main(request):
Thread(target=do_something).start()
responce = {'status': 'started!'}
return responce
It works only if do_something() doesn't contain threads inside. Please, help with the usage of async-await here 'without extra code lines'
[update] this works fine only in Jupyter, but not in docker container(there yields 'RuntimeError: There is no current event loop in thread'):
import asyncio
async def do_something():
print("internal training started")
await asyncio.sleep(5)
print("internal training finished")
def main():
asyncio.ensure_future(train_models())
responce = {'status': 'started!'}
return responce
print(main())
[update] the problem was not with threads ans asynchronous functions, the problem was with azure-functions. [closed]