-
Notifications
You must be signed in to change notification settings - Fork 16
Switch await core.sleep
to await core.io_queue.queue_[read|write]
#33
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
Conversation
I may add some further examples for UART and bluetooth buffers as well |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I switched the sleeps to yield
because I thought it was a misuse of yield
. My understanding is that this code would not work in CPython: yield
is reserved for actual generators.
@jepler fixed this in another part of the library by writing a special "Never" class. You could use that same class (the code might not a bit of refactoring. @jepler do you have a comment here?
See #30 for use of the |
I agree, this is probably the same problem again, just in code we weren't testing. If changing to 'yield' works, then changing to use the never class will probably work also, while allowing our linters and more importantly our doc-builder to work with the code. |
also, super stoked to see the examples, thank you! |
As mentioned in #30:
It seems to me it should An interesting point raised in an asyncio tutorial:
|
I did refactor a bit so that diff --git a/asyncio/core.py b/asyncio/core.py
index dcd4b24..f1994eb 100644
--- a/asyncio/core.py
+++ b/asyncio/core.py
@@ -94,11 +94,11 @@ def sleep(t):
################################################################################
# "Never schedule" object"
-# Don't re-schedule the object that awaits the _never singleton.
+# Don't re-schedule the object that awaits _never().
# For internal use only. Some constructs, like `await event.wait()`,
# work by NOT re-scheduling the task which calls wait(), but by
# having some other task schedule it later.
-class _Never:
+class _NeverSingletonGenerator:
def __init__(self):
self.state = None
self.exc = StopIteration()
@@ -117,7 +117,10 @@ class _Never:
self.exc.__traceback__ = None
raise self.exc
-_never = _Never()
+def _never(sgen=_NeverSingletonGenerator()):
+ # assert sgen.state is None, "Check for a missing `await` in your code"
+ sgen.state = False
+ return sgen
################################################################################
diff --git a/asyncio/event.py b/asyncio/event.py
index 442c5bb..164a269 100644
--- a/asyncio/event.py
+++ b/asyncio/event.py
@@ -62,8 +62,7 @@ class Event:
self.waiting.push_head(core.cur_task)
# Set calling task's data to the event's queue so it can be removed if needed
core.cur_task.data = self.waiting
- core._never.state = False
- await core._never
+ await core._never()
return True
diff --git a/asyncio/lock.py b/asyncio/lock.py
index b5080a3..71c972f 100644
--- a/asyncio/lock.py
+++ b/asyncio/lock.py
@@ -69,8 +69,7 @@ class Lock:
# Set calling task's data to the lock's queue so it can be removed if needed
core.cur_task.data = self.waiting
try:
- core._never.state = False
- await core._never
+ await core._never()
except core.CancelledError as er:
if self.state == core.cur_task:
# Cancelled while pending on resume, schedule next waiting Task |
It seems a bit odd to have a bunch of places where |
Seems logical to me, but I'd also look to see if something similar is done in CPython asyncio. |
…rning. Also update streams.py to reflect this and provide example code for using UART, USB_CDC and BLE
await core.sleep
to yield
await core.sleep
to await core.io_queue.queue_[read|write]
CPython asyncio doesn't seem to have much similarity with the circuitpython code for stream management. I've therefore converted to make IOQueue.queue_read/write methods coroutines. |
Looks like as of today we are running pre-commit hooks on python 3.11. This conflicts with pylint 2.11.1 - so I've upgraded the pylint requirement for pre-commit to 2.13.9 |
One remaining issue is error correction. I note that with the BLE UART I need to pass in Should we have some checks on initialisation that we are passing an appropriate object in (and then access the ble |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I fixed the merge conflict in pre-commit
Updating https://github.com/adafruit/Adafruit_CircuitPython_AS7341 to 1.2.12 from 1.2.11: > Merge pull request adafruit/Adafruit_CircuitPython_AS7341#32 from adafruit/pylint-fix > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_BluefruitSPI to 1.1.15 from 1.1.14: > Merge pull request adafruit/Adafruit_CircuitPython_BluefruitSPI#26 from adafruit/pylint-fix > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_BME280 to 2.6.18 from 2.6.17: > Merge pull request adafruit/Adafruit_CircuitPython_BME280#64 from adafruit/pylint-fix > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_CharLCD to 3.4.5 from 3.4.4: > Merge pull request adafruit/Adafruit_CircuitPython_CharLCD#75 from adafruit/pylint-fix Updating https://github.com/adafruit/Adafruit_CircuitPython_DHT to 3.7.8 from 3.7.7: > Merge pull request adafruit/Adafruit_CircuitPython_DHT#85 from adafruit/pylint-fix > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_DRV2605 to 1.2.8 from 1.2.7: > Merge pull request adafruit/Adafruit_CircuitPython_DRV2605#32 from adafruit/pylint-fix > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_FONA to 2.1.14 from 2.1.13: > Merge pull request adafruit/Adafruit_CircuitPython_FONA#22 from adafruit/pylint-fix > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_IRRemote to 4.1.11 from 4.1.10: > Merge pull request adafruit/Adafruit_CircuitPython_IRRemote#55 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS to 4.5.6 from 4.5.5: > Merge pull request adafruit/Adafruit_CircuitPython_LSM6DS#58 from adafruit/pylint-fix > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_MAX31855 to 3.2.18 from 3.2.17: > Merge pull request adafruit/Adafruit_CircuitPython_MAX31855#29 from adafruit/pylint-fix > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_MAX31856 to 0.11.4 from 0.11.3: > Merge pull request adafruit/Adafruit_CircuitPython_MAX31856#24 from adafruit/pylint-fix > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_MAX31865 to 2.2.18 from 2.2.17: > Merge pull request adafruit/Adafruit_CircuitPython_MAX31865#39 from adafruit/pylint-fix > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_MAX7219 to 1.5.9 from 1.5.8: > Merge pull request adafruit/Adafruit_CircuitPython_MAX7219#44 from adafruit/pylint-fix > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_MCP2515 to 1.0.18 from 1.0.17: > Merge pull request adafruit/Adafruit_CircuitPython_MCP2515#14 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_MCP3xxx to 1.4.13 from 1.4.12: > Merge pull request adafruit/Adafruit_CircuitPython_MCP3xxx#39 from adafruit/pylint-fix > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_MLX90640 to 1.2.13 from 1.2.12: > Merge pull request adafruit/Adafruit_CircuitPython_MLX90640#31 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_OV2640 to 1.1.9 from 1.1.8: > Merge pull request adafruit/Adafruit_CircuitPython_OV2640#21 from adafruit/disable-lambda-check > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_RFM9x to 2.2.13 from 2.2.12: > Merge pull request adafruit/Adafruit_CircuitPython_RFM9x#85 from adafruit/pylint-fix > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_SD to 3.3.16 from 3.3.15: > Merge pull request adafruit/Adafruit_CircuitPython_SD#53 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_TrellisM4 to 1.5.15 from 1.5.14: > Merge pull request adafruit/Adafruit_CircuitPython_TrellisM4#30 from adafruit/pylint-fix > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_VL53L1X to 1.1.7 from 1.1.6: > Merge pull request adafruit/Adafruit_CircuitPython_VL53L1X#12 from adafruit/pylint-fix > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_VS1053 to 1.2.15 from 1.2.14: > Merge pull request adafruit/Adafruit_CircuitPython_VS1053#19 from adafruit/pylint-fix > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k to 1.12.15 from 1.12.14: > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#74 from tekktrik/dev/fix-pylint > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_asyncio to 0.5.18 from 0.5.17: > Merge pull request adafruit/Adafruit_CircuitPython_asyncio#34 from jepler/improve-await-never > Merge pull request adafruit/Adafruit_CircuitPython_asyncio#33 from furbrain/main > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_AVRprog to 1.4.10 from 1.4.9: > Merge pull request adafruit/Adafruit_CircuitPython_AVRprog#33 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_AzureIoT to 2.5.12 from 2.5.11: > Merge pull request adafruit/Adafruit_CircuitPython_AzureIoT#54 from adafruit/pylint-fix > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE to 9.0.1 from 9.0.0: > Merge pull request adafruit/Adafruit_CircuitPython_BLE#176 from adafruit/pylint-fix > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE_File_Transfer to 4.0.4 from 4.0.3: > Merge pull request adafruit/Adafruit_CircuitPython_BLE_File_Transfer#22 from tekktrik/dev/fix-version > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions > Standardize build.yml Updating https://github.com/adafruit/Adafruit_CircuitPython_Dash_Dis to 1.1.13 from 1.1.12: > Merge pull request adafruit/Adafruit_CircuitPython_Dash_Dis#8 from tekktrik/dev/fix-pylint-error > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_datetime to 1.2.3 from 1.2.2: > Merge pull request adafruit/Adafruit_CircuitPython_datetime#21 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing to 1.14.11 from 1.14.10: > Merge pull request adafruit/Adafruit_CircuitPython_FeatherWing#79 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_hashlib to 1.4.10 from 1.4.9: > Merge pull request adafruit/Adafruit_CircuitPython_hashlib#21 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer to 0.5.4 from 0.5.3: > Merge pull request adafruit/Adafruit_CircuitPython_HTTPServer#23 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update README > Remove no-self-use disable > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_IterTools to 2.0.4 from 2.0.3: > Merge pull request adafruit/Adafruit_CircuitPython_IterTools#18 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_Logging to 5.0.1 from 5.0.0: > Merge pull request adafruit/Adafruit_CircuitPython_Logging#42 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_MIDI to 1.4.14 from 1.4.13: > Merge pull request adafruit/Adafruit_CircuitPython_MIDI#51 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_miniQR to 1.3.15 from 1.3.14: > Merge pull request adafruit/Adafruit_CircuitPython_miniQR#21 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_ProgressBar to 2.3.9 from 2.3.8: > Merge pull request adafruit/Adafruit_CircuitPython_ProgressBar#37 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_PyBadger to 3.7.9 from 3.7.8: > Merge pull request adafruit/Adafruit_CircuitPython_PyBadger#63 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_RSA to 1.2.16 from 1.2.15: > Merge pull request adafruit/Adafruit_CircuitPython_RSA#37 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO to 3.0.9 from 3.0.8: > Merge pull request adafruit/Adafruit_CircuitPython_SimpleIO#66 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_TinyLoRa to 2.2.12 from 2.2.11: > Merge pull request adafruit/Adafruit_CircuitPython_TinyLoRa#48 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_turtle to 2.2.12 from 2.2.11: > Merge pull request adafruit/Adafruit_CircuitPython_turtle#32 from tekktrik/dev/fix-pylint-errors > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions
This is a fix for issue #32