-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
aiogrpc
RuntimeError
#698
Comments
Digging further, it seems the error is thrown (raised) internally as wrapping the whole code in a try...except block doesn't catch it. |
I have seen similar annoying exceptions when using it more recently. Can you run mavsdk_server separate and check whether it doesn't crash or lockup? |
I ended up doing something like this, not sure if that would help your case:
|
That's what I am doing. I am using windows which means I have to start the server process right before each connection: async def start_mavsdk_server(connection_url: str, port: int):
cmd = [resource_path('include/mavsdk_server.exe'), "-p", str(port), connection_url]
mavsdk_server_process = Popen(
cmd,
stdout=PIPE,
stderr=PIPE,
universal_newlines=True,
start_new_session=True,
)
return mavsdk_server_process Still raises the exception |
Would try adding this to my event generator and seeing if it helps 👍. Does this restart the entire app or just the mavsdk server? Due to the nature of sockets, restarting the entire app would pose an issue due to socket client behaviour. Would I also need to restart mavsdk server manually after stopping the event loop? |
For me this restarts the full app which is a quart server in my case. |
I get a similar error when running the examples. However it seems to be intermittent (The worst kind of error :) ) Takeoff and Land: #!/usr/bin/env python3
import asyncio
from mavsdk import System
async def run():
drone = System()
await drone.connect(system_address="udp://:14540")
status_text_task = asyncio.ensure_future(print_status_text(drone))
print("Waiting for drone to connect...")
async for state in drone.core.connection_state():
if state.is_connected:
print(f"-- Connected to drone!")
break
print("Waiting for drone to have a global position estimate...")
async for health in drone.telemetry.health():
if health.is_global_position_ok and health.is_home_position_ok:
print("-- Global position estimate OK")
break
print("-- Arming")
await drone.action.arm()
print("-- Taking off")
await drone.action.takeoff()
await asyncio.sleep(10)
print("-- Landing")
await drone.action.land()
#status_text_task.cancel()
async def print_status_text(drone):
try:
async for status_text in drone.telemetry.status_text():
print(f"Status: {status_text.type}: {status_text.text}")
except asyncio.CancelledError:
return
if __name__ == "__main__":
# Run the asyncio loop
asyncio.run(run()) It runs seemingly ok. Drone takes off and lands. but then it throws the error: python test1.py
Waiting for drone to connect...
-- Connected to drone!
Waiting for drone to have a global position estimate...
-- Global position estimate OK
-- Arming
-- Taking off
Status: INFO: Armed by external command
Status: INFO: Using default takeoff altitude: 10.0 m
Status: INFO: [logger] ./log/2024-05-20/23_47_00.ulg
Status: INFO: Using default takeoff altitude: 10.0 m
Status: INFO: Takeoff detected
-- Landing
Exception ignored in: <function WrappedIterator.__del__ at 0x710c78765750>
Traceback (most recent call last):
File "/home/dave/.local/lib/python3.10/site-packages/aiogrpc/utils.py", line 168, in __del__
self._stream_executor.shutdown()
File "/usr/lib/python3.10/concurrent/futures/thread.py", line 235, in shutdown
t.join()
File "/usr/lib/python3.10/threading.py", line 1093, in join
raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread
|
@JonasVautherin any ideas? |
Getting a new error, still stemming from aiogrpc:
This occurs more rarely, but it gives my systems a bit of unpredictability when trying to read telemetry consistently Any ideas? cc @JonasVautherin |
Overall, I am thinking if it's possible to dump aiogrpc (which hasn't been updated in 4 years) and roll with something like: grpclib which still receives updates and works natively with asyncio? I am not sure how tightly coupled this project is with aiogrpc. Would take a look at the feasibility of such conversion 👍 |
It doesn't look too complicated to facilitate a switch, but I do not know what I am doing yet. |
I didn't realize we could swap out |
Is this something you intend on working on in the near future? |
Probably not in the next couple of weeks. Is this urgent for you, or are you asking to try yourself? |
Both. It's a bit urgent, and I am wondering if I can do it. Asides changing imports in the async plugin manager, I am not sure if I would need to re-generate any file or the current proto files generation are good to go |
If it has a similar API to aiogrpc, maybe it's actually easy to swap 👍. I would say just try it and see where it goes 😊. |
I wouldn't know but all I find is this: https://github.com/search?q=repo%3Amavlink%2FMAVSDK-Python%20aiogrpc&type=code But at @ShafSpecs, I assume you're aware of how to do the generation as outlined here: |
I am on windows, and it just hit me at the moment that I won't be able to run the necessary scripts. Maybe I could convert them to ps scripts? I don't know and the bash scripts seem to utilise native unix modules. I might just wait out the few weeks before you can implement it |
I would just do it in WSL2 or docker if I was you, but up to you. |
Apparently, the official I also noticed that when I setup the package for local development, it correctly links to mavsdk_server, meaning I don't need to start it up myself. But in the actual package, it needs to be manually started on Windows. Do you know the reason why? I suppose I can also try and tackle that issue too |
Checking the git history, most of the grpc files were generated ~5 yrs ago (as well as outdated dependencies). I am trying to regenerate it on my end but running into an issue with |
Not sure what you mean. Most of these files are autogenerated. Some haven't changed in years, but that means that the API is stable 😊. Don't forget that MAVSDK-Python just relays the API to MAVSDK-C++. E.g. the API of the camera plugin hasn't changed much (that's API stability), but the implementation (in C++) has changed. |
Oh okay. There is a dependency conflict currently in the project that was making me wonder, in the dev requirements - caused by Note I tried to vary versions, but
Edit:
|
Attempted to fix the issues I noticed in the |
I was able to regenerate all files as well as remove aiogrpc completely, in spite of all that, there are a few examples that still hang up indefinitely (e.g calibration) In light of this, I have decided to open a PR (soon) in this repo to address the aiogrpc issue and leave the rest for another time. The freezing is a baffling issue that seems to have no reason, and it also means that some features of mavsdk unusable (e.g mission tracking, etc.). Thank you |
@JonasVautherin you work at Auterion, right? Love the company btw, a favorite of mine. How do you guys handle the MAVLink part of communication? Do you use the CPP version of MAVSDK straight up? Or mavlink? I want to work with mavsdk without having to pre-check working/non-working plugins. Which would you advise? Thanks for the help |
What exactly do you mean? I mostly use MAVSDK C++ unless I specifically need Python. Use cases for that for me are quick scripting, or recently a quart webserver backend. |
Ah okay. I was taking a look at the python and the cpp of mavsdk. And the cpp seems more fleshed out. I was using electron and Python previously for my simple gcs but I am considering Qt instead thanks to the C++ backend - with mavsdk-cpp Plus, it allows me to learn cpp. I'm much familiar with Rust than CPP |
I checked it out. Doesn't seem fully fleshed out like python or cpp, especially for a well rounded gcs. |
No, not anymore. I just try to help @julianoes with MAVSDK when I can, in my free time 😊. |
Cool. Hopefully, I can learn enough to help consistently as well 🚀. |
Using my own local MAVSDK (with swapped out # for example, invoking this just hangs the entire app
async def get_status_text(vehicle: System):
async for status in vehicle.telemetry.status_text():
return {
"text": status.text,
"type": status.type.__str__()
}
# or
async def get_battery(vehicle: System):
async for battery in vehicle.telemetry.battery():
return {
"voltage_v": battery.voltage_v,
"current_battery_a": battery.current_battery_a,
"remaining_percent": int(battery.remaining_percent),
"capacity_consumed_ah": battery.capacity_consumed_ah,
"temperature_degc": battery.temperature_degc,
"id": battery.id
} I get a weird error from
Does this indicate an error on the mavsdk server side? Hope not 🫣 |
It feels like the connection between the gRPC client and the gRPC server broke. Could it be that mavsdk_server crashed? |
I am assuming so. I would try to run mavsdk_server on its own so I can get logs from it and check the source of error 👍 |
Hello, so I was building a simple GCS. A simple UI on the front and a python server at the back.
Using websocket to handle commands and Server-Sent Events (SSE) for unidirectional information (telemetry). Whilst building out the telemetry aspect, I noticed that RuntimeError randomly got thrown.
Depending on how I structured the SSE route, it got thrown frequently or once in a while. A basic structure:
The error comes from mavsdk dependency:
aiogrpc
. I am not well-versed with multi-threading in python but I assume the issue stems from aiogrpc creating its own threads and attempting to join them. Is there any way I can disable that? Possibly useasyncio
fully for running tasks on a separate thread? Or maybe find a fix I am overlooking. ThanksThe text was updated successfully, but these errors were encountered: