5 ms·
Show HN: Python micro event loop library (~250 LOC)
- vram22 2y agoIt's 736 LOC now. Last 2 lines, 735 and 736: # Start the event loop with the main coroutine event_loop(main())
- Gys 2y agoThat is counting all comments and empty lines, which are many.
- tarruda 2y agoIf you count only the library code, it is less than 250 LOC. I then asked for Claude to write the docstrings and examples which increased by 500
- d0mine 2y agoIt reminded me of pycon talk by David Beazley - Python Concurrency From the Ground Up: LIVE! - PyCon 2015 https://www.youtube.com/watch?v=MCs5OvhV9S4 https://www.youtube.com/watch?v=MCs5OvhV9S4 What is the purpose of @dataclass on Task class?
- tarruda 2y ago> What is the purpose of @dataclass on Task class? No purpose. I think I added in the initial implementation and ended up not being required, but I forgot to remove
- dnadler 2y agoI haven’t kept up with python too much over the past year or two and learned a couple new things from this code. Namely, match/case and generic class typing. Makes me wonder what else is new, off to the python docs!
- svilen_dobrev 2y agothanks for pointing that out. Seems a thorough scan as features of whatsnew is due - since maybe 3.7? For the record, ~language~ additions i found interesting (excluding type-hints): 3.11: (Base)ExceptionGroups ; (Base)Exception.add_note() + __notes__ modules: tomllib 3.10: Parenthesized context managers Structural Pattern Matching - match..:case.. builtins: aiter(), anext() 3.9: dict | dict ; dict |= dict for a in *x,*y: ... #no need of (*x,*y) str.removeprefix , str.removesuffix Any valid expression can now be used as a decorator modules: zoneinfo , graphlib 3.8: Assignment expressions Positional-only parameters f'{expr=}' Dict comprehensions and literals compute First the key and Second value 3.7: builtins: breakpoint() __getattr__ and __dir__ of modules modules: contextvars , dataclasses
- hyperbrainer 2y agoThere was also the walrus operator
- svilen_dobrev 2y agothat's the Assignment expressions, i.e. :=
- hyperbrainer 2y agoTrue, I did not see that. My bad, sorry!
- d0mine 2y agoMisc: 3.10 zip(strict=True) 3.11 asyncio.TaskGroup (structured concurrency) enabled by ExceptionGroup 3.12 itertools.batched(L, n) — it replaces zip([iter(L)]n)
- somesun 2y agovery good example to learn async , will try it