Closed sei-jmattson closed 9 hours ago
While I understand the annoyance, it's probably best that you monkey patch this. My hesitation is that while this exception is of low value in response to garbage collection triggered by a SIGINT, it is valuable if you're managing multiple event loops or starting/stopping one and expect your DatagramStreams to close first (presumably after alerting the other side). Or even if you just have an expectation that your code provides a way to implement a graceful shutdown.
The "correct" way to deal with your issue is probably to add a signal handler or write a context manager that makes sure the DatagramStreams are correctly closed before garbage collection starts. This is the approach I've taken when using this package. Depending on the context, monkey-patching is probably appropriate when weighed against the amount of work required to implement a graceful shutdown.
That said, I'm open to being otherwise convinced.
Sounds reasonable. Thanks.
This is largely a cosmetic recommendation...
DatagramStream can be garbage collected after the asyncio loop is ended (e.g. Ctrl-C in a terminal cli), causing messy output of
RuntimeError('Event loop is closed')
for each instance.I'm content to monkey-patch it in my app, but thought I'd drop a note.