Issue
I am trying to use the asyncio
in my code. This is working, but the problem is I want my code to keep executing instead it keep waiting for the asyncio
code to complete execution.
In the current scenario my code keep waiting for the asyncio code result = asyncio.run(run())
to complete before moving onto the next line of code.
I think my asyncio code needs to be executed on the new thread. But how can I make it work?
I am using Django.
def Dashboard(requests):
result = asyncio.run(run())
all_Farm = MyCollection.objects.all().filter(userid=requests.user.id)
return render(requests, 'Dashboard.html',
{'all_farm': all_Farm})
async def run():
drone = System()
await drone.connect(system_address="udp://:14540")
print("Waiting for drone to connect...")
async for state in drone.core.connection_state():
if state.is_connected:
print(f"Drone discovered with UUID: {state.uuid}")
break
print("Waiting for drone to have a global position estimate...")
async for health in drone.telemetry.health():
if health.is_global_position_ok:
print("Global position estimate ok")
break
print("-- Arming")
await drone.action.arm()
print("-- Taking off")
await drone.action.takeoff()
await asyncio.sleep(5)
print("-- Landing")
await drone.action.land()
Solution
After doing some more research on this topic of running async methods in Django, I found a solution that actually worked in my case.
The solution that I found is CELERY. I found this from here. Celery works perfectly fine along with Django.
Answered By - Khaksar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.