-
Notifications
You must be signed in to change notification settings - Fork 109
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
Asyncio Testing #60
base: master
Are you sure you want to change the base?
Asyncio Testing #60
Conversation
Not shure if this is the right derection or not thoughts?
_attemps is depercataed
I like the idea of asyncio in principal, but I haven't tested it as I'm away from home (and hence the Sim). |
@danricho just thinking about removing attempts, Python-SimConnect/SimConnect/SimConnect.py Lines 163 to 165 in 152fa14
_run Python-SimConnect/SimConnect/SimConnect.py Lines 172 to 175 in 152fa14
Data is revived by Python-SimConnect/SimConnect/SimConnect.py Lines 243 to 249 in 152fa14
normally attempts are check in the while loop (Line 244) to escape if data is not received in a given time. I don't know if this is still needed or wanted with the new async bits. With time, it is how long to return cashed data vs new data form the sim. Python-SimConnect/SimConnect/RequestList.py Lines 15 to 24 in 152fa14
|
Just tested this last version of the asyncio branch for a good 45 min reading altitude/long/lat/baro with another instance giving command and so far very stable and received no None value. |
I haven't tested this PR, but I was just considering writing an async wrapper around my calls to Python-SimConnect so I hit fewer cases of needing to handle a |
I tested this change this morning and have found it flawless. It enabled me to log flight parameters at a much higher frequency than the old method which essentially hangs until a value is received. Only limitation I found is the returning of 'None's when I used get() on signals with an index (eg: 'x:1') or the wind direction/speed. But I used request in setup then .value() in the main loop to get around this. I didn't figure out why this happened. |
updated asyncio
so with such a big change how should we make handle the move? |
new sample, added an a to the async vertions of functions to keep backwords code woking.
Sample: from SimConnect import *
import logging
from SimConnect.Enum import *
from time import sleep
import asyncio
logging.basicConfig(level=logging.DEBUG)
LOGGER = logging.getLogger(__name__)
LOGGER.info("START")
# creat simconnection and pass used user classes
sm = SimConnect()
aq = AircraftRequests(sm, _time=10, _attemps=10)
Throttle = aq.find('GENERAL_ENG_THROTTLE_LEVER_POSITION:1')
# none async Function still works
print("Throttle:", Throttle.value)
print("Alt=%f Lat=%f Lon=%f Kohlsman=%.2f" % (
aq.PositionandSpeedData.get('PLANE_ALTITUDE'),
aq.PositionandSpeedData.get('PLANE_LATITUDE'),
aq.PositionandSpeedData.get('PLANE_LONGITUDE'),
aq.FlightInstrumentationData.get('KOHLSMAN_SETTING_HG')
))
# New async Function
async def PrintData():
# THROTTLE Request
print("Throttle:", await Throttle.avalue)
print("Lat=%f Lon=%f Alt=%f Kohlsman=%.2f" % tuple(
await asyncio.gather(
aq.PositionandSpeedData.aget('PLANE_LATITUDE'),
aq.PositionandSpeedData.aget('PLANE_LONGITUDE'),
aq.PositionandSpeedData.aget('PLANE_ALTITUDE'),
aq.FlightInstrumentationData.aget('KOHLSMAN_SETTING_HG')
)
))
asyncio.run(PrintData())
sm.exit()
quit() |
My opinion: Follow semantic versioning. If this is a breaking change to old code, increment the major version number. It's on us as library users if we failed to pin the version correctly. Unless there's a good reason to maintain both versions of the functions, don't. |
I do agree that library users should be managing library versions and that we shouldn't keep both versions side by side due to maintenance burden; however I have a few thoughts that might help or at least ease the transition:
I only suggest this as there seems to be quite a number of users now. |
I'd like to report the following bug I've noticed: The asyncio version doesn't work when getting two SimVars with the same key but different index consecutively. Example:
NAV2_OBS_DEG will be getting the NAV_OBS:1 value. The code works, however, when I introduce a different key inbetween. Like this:
This issue has been introduced with asyncio version and hasn't been a problem before. I'm not sure if it's a problem on my part or it's a bug in general. Unfortunately, my Python skills aren't up to the skills to propose a bug fix. Thanks! |
Thanks @danricho. This seems to explain the behavior and I understand the performance reasons. Hopefully, I'll be able to come up with a solution on how to efficiently get the NAV OBSs myself. Again, I'm not a Python pro. :) |
If you post your code, I or someone else could help you adjust it to get this working. |
Hi guys, let's go async ;-) Please test. |
Not shure if this is the right direction or not thoughts?