feat: added aio MessageBus 'loop' optional parameter#560
feat: added aio MessageBus 'loop' optional parameter#560depaolim wants to merge 2 commits intoBluetooth-Devices:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #560 +/- ##
=======================================
Coverage 85.31% 85.32%
=======================================
Files 28 28
Lines 3433 3435 +2
Branches 601 602 +1
=======================================
+ Hits 2929 2931 +2
Misses 312 312
Partials 192 192 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
CodSpeed Performance ReportMerging #560 will not alter performanceComparing Summary
|
|
Can you tell us more about the specific case? We will need to add this paramter to the documentation comment as well. And it should have an explanation that discourages people from actually using the parameter. An example of an legitimate use case would help. And we should add |
I think a common legitimate use case is when creating a multi-threaded application where different threads need their own event loops.
In this scenario, you can't use asyncio.get_running_loop() in the worker thread because you need to explicitly create and manage a separate event loop for that thread. If I'm missing something, please let me know. |
|
I would expect that one would create the asyncio event loop first by calling |
You made a point. I double check my scenario and I'll be back with some news |
|
Here I am, finally back. I’m submitting a few points of reflection; in any case, I really appreciate this repository, so I’ll trust your judgment on whether introducing this parameter is appropriate.
As I mentioned, I trust your judgment. I agree that the parameter isn’t strictly essential, so I’m also fine with closing the PR without merging. |
It would only fail if the run loop isn't running. So passing
I'm not sure I understand this one. My understanding is that
This would be a very rare exception. I would expect a thread used for D-Bus to be used only for that and not be using the executor for other things.
There are also a lot of cases where a So basically, if we find a real-world use case where it is actually needed, then sure, we can add it. But otherwise I would be inclined to leave it the way it is so that people are not tempted to use it incorrectly. |
That's fine with me |
|
I'm sorry, I reopened it by mistake... Now I'm closing it again |
Added the optional loop parameter to asyncio's MessageBus object. If not specified, it uses the running_loop parameter as before. This can be useful for special cases where the programmer needs to execute operations in a specific loop of their choosing.