Skip to content

Commit

Permalink
examples: switch to newer asyncio API
Browse files Browse the repository at this point in the history
Available since Python 3.7.

Signed-off-by: Julian Oes <[email protected]>
  • Loading branch information
julianoes committed Jan 13, 2023
1 parent f6798f5 commit 87a7aef
Show file tree
Hide file tree
Showing 27 changed files with 56 additions and 66 deletions.
4 changes: 2 additions & 2 deletions examples/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ async def run():


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
4 changes: 2 additions & 2 deletions examples/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ async def print_status(drone):


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
4 changes: 2 additions & 2 deletions examples/camera_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,5 @@ async def make_user_choose_option_range(possible_options):


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
4 changes: 2 additions & 2 deletions examples/failure_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ async def run():
await drone.param.set_param_int('SYS_FAILURE_EN', 0)

if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
4 changes: 2 additions & 2 deletions examples/firmware_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ async def run():


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
4 changes: 2 additions & 2 deletions examples/follow_me_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ async def fly_drone():
await drone.action.land()

if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(fly_drone())
# Run the asyncio loop
asyncio.run(run())
6 changes: 3 additions & 3 deletions examples/geofence.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
This example shows how to use the geofence plugin.
Note: The behavior when your vehicle hits the geofence is NOT configured in this example.
Note: The behavior when your vehicle hits the geofence is NOT configured in this example.
"""

Expand Down Expand Up @@ -51,5 +51,5 @@ async def run():


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
5 changes: 2 additions & 3 deletions examples/gimbal.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,5 @@ async def print_gimbal_position(drone):


if __name__ == "__main__":
# Start the main function
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
4 changes: 2 additions & 2 deletions examples/goto.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ async def run():


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
3 changes: 2 additions & 1 deletion examples/logfile_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ async def get_entries(drone):


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
5 changes: 2 additions & 3 deletions examples/manual_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,5 @@ async def manual_controls():


if __name__ == "__main__":

loop = asyncio.get_event_loop()
loop.run_until_complete(manual_controls())
# Run the asyncio loop
asyncio.run(run())
4 changes: 2 additions & 2 deletions examples/mission.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,5 @@ async def observe_is_in_air(drone, running_tasks):


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
4 changes: 2 additions & 2 deletions examples/mission_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ async def run():


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
4 changes: 2 additions & 2 deletions examples/offboard_attitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ async def run():


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
4 changes: 2 additions & 2 deletions examples/offboard_position_ned.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ async def run():


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
4 changes: 2 additions & 2 deletions examples/offboard_position_velocity_ned.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ async def print_z_velocity(drone):


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
4 changes: 2 additions & 2 deletions examples/offboard_velocity_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ async def run():


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
4 changes: 2 additions & 2 deletions examples/offboard_velocity_ned.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ async def run():


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
4 changes: 2 additions & 2 deletions examples/send_status_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ async def run():
break

if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
4 changes: 2 additions & 2 deletions examples/takeoff_and_land.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ async def print_status_text(drone):


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
5 changes: 2 additions & 3 deletions examples/takeoff_and_land_keyboard_control.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Author: @woosal1337
"""
#!/usr/bin/env python3

import asyncio
import pygame
Expand Down Expand Up @@ -148,6 +146,7 @@ async def print_position(drone=drone):

if __name__ == "__main__":

# TODO: use new asyncio methods
loop = asyncio.get_event_loop()
loop.run_until_complete(setup())
loop.run_until_complete(main())
Expand Down
7 changes: 2 additions & 5 deletions examples/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,5 @@ async def print_position(drone):


if __name__ == "__main__":
# Start the main function
asyncio.ensure_future(run())

# Runs the event loop until the program is canceled with e.g. CTRL-C
asyncio.get_event_loop().run_forever()
# Run the asyncio loop
asyncio.run(run())
4 changes: 2 additions & 2 deletions examples/telemetry_flight_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ async def print_flight_mode():


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(print_flight_mode())
# Run the asyncio loop
asyncio.run(run())
7 changes: 2 additions & 5 deletions examples/telemetry_is_armed_is_in_air.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@ async def print_is_in_air(drone):


if __name__ == "__main__":
# Start the main function
asyncio.ensure_future(run())

# Runs the event loop until the program is canceled with e.g. CTRL-C
asyncio.get_event_loop().run_forever()
# Run the asyncio loop
asyncio.run(run())
3 changes: 2 additions & 1 deletion examples/telemetry_takeoff_and_land.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,5 @@ async def observe_is_in_air(drone, running_tasks):


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())
9 changes: 3 additions & 6 deletions examples/transponder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async def run():
drone = System()
#await drone.connect(system_address="udp://:14540")
await drone.connect()

# Start the tasks
asyncio.ensure_future(print_transponders(drone))

Expand All @@ -19,8 +19,5 @@ async def print_transponders(drone):


if __name__ == "__main__":
# Start the main function
asyncio.ensure_future(run())

# Runs the event loop until the program is canceled with e.g. CTRL-C
asyncio.get_event_loop().run_forever()
# Run the asyncio loop
asyncio.run(run())
4 changes: 2 additions & 2 deletions examples/tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ async def run():
print("Tune played")

if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
# Run the asyncio loop
asyncio.run(run())

0 comments on commit 87a7aef

Please sign in to comment.