Open lneuhaus opened 5 years ago
So what's your opinion on these ?
Sorry for the delay.
So we agree that ANYTHING_async returns a future, and ANYTHING awaits the result and returns after that, right? I agree that all functions should have these two versions.
lock/lock_async
. There is however a function lock
at the moment, right? timeout=0
(0=no timeout) and retry_times=1
(0=infinite times). These would make lock_until_locked
obsolete. We could however add these on top (basically calling lock_async(retry_times=0)
sleep_while_locked
should be useful, I agree. Can this not be a two-liner in python3? In any case, either it saves many lines, or it serves as a nice example. On top of this, I find it useful to allow passing arguments to lock() that modify the final locking stage, e.g. lock(setpoint=-0.5, gain=2)
. There is currently some kind of overcomplicated code with final_stage
that was implemented around this, i.e. final_stage
is a duplicate of the last element of stages
with its properties overwritten by the arguments passed to lock
. This way, relock()
would be able to use this modified setpoint, while lock
would execute the default locking sequence. If you have the time to debug it after changing, I would be okay with the removal of all the special treatment of final_stage
and let the last stage be the last element of stages
. I would however still allow to pass arguments such as setpoint
to lock()
which then simply overwrite the values in the default stage. If a user wants to return to a previous "default" sequence, the way to go would be to load a stored locking sequence. If you strongly dislike that, I would favor having a convenience function, e.g. lock_modify_setpoint
, but I think this overcomplicates things.
Absolutely, you are right about the _async postfix and the return types. At the moment, there is a lock function but it is returning immediately as you would expect from lock_async instead of blocking until the lock is effective.
for sleep_while_locked, I would probably use the wait function that's defined in async_utils with a timeout. And create a coroutine that returns only when the cavity unlocks by awaiting an unlock event https://docs.python.org/3/library/asyncio-sync.html#asyncio.Event
I can do these updates relatively simply, including removing the final_stage stuff as long as it's only the python3-only branch. Otherwise, I have the feeling I will have to duplicate a lot of stuffs.
By the way, unittests seem to be fine again on python2.7 on develop0.9.3
Sounds good to me, I do not think we need the API changes in Python 2.
Here is a copy-paste from issue #349:
But also, I am proposing below a few modification to the Lockbox API for consistency. Moreover, I realize that the unittetsts for these functionalities are quite limited, I will try to add some more unittests as well.