Skip to content
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

[v3 cog manager, utils] handle missing cogs correctly, add some helpful algorithms #1989

Merged

Conversation

calebj
Copy link
Member

@calebj calebj commented Aug 7, 2018

Type

  • Bugfix
  • Enhancement
  • New feature

Description of the changes

For cog loading, only show "cog not found" if the module in question was the one that failed to import. ImportErrors within cogs will now show an error as they should.

Also:

  • Add a chain deduplicator, benchmarked to be the fastest method
  • Add a semaphore-bounded variant of asyncio.gather and an async as_completed
  • And of course, tests and docs for all additions

@calebj calebj force-pushed the v3/cog_manager_fix_async_utils branch from 075d7ed to e81d875 Compare August 7, 2018 03:38
@calebj calebj requested a review from palmtree5 as a code owner August 7, 2018 03:38
@Tobotimus Tobotimus added the V3 label Aug 7, 2018
@calebj calebj force-pushed the v3/cog_manager_fix_async_utils branch from e81d875 to 100f0e5 Compare August 7, 2018 10:38
@Tobotimus Tobotimus added this to the Future release milestone Aug 7, 2018
@calebj calebj force-pushed the v3/cog_manager_fix_async_utils branch from 100f0e5 to 45450c8 Compare August 8, 2018 02:29
@Tobotimus Tobotimus added QA: Unassigned Type: Enhancement Something meant to enhance existing Red features. and removed QA: Needed labels Aug 13, 2018
For cog loading, only show "cog not found" if the module in question was the one
that failed to import. ImportErrors within cogs will show an error as they should.

- deduplicator, benchmarked to be the fastest
- bounded gather and bounded async as_completed
- tests for all additions
@calebj calebj force-pushed the v3/cog_manager_fix_async_utils branch from 45450c8 to 3e47dcb Compare August 18, 2018 06:39
@calebj
Copy link
Member Author

calebj commented Aug 18, 2018

@Tobotimus rebased.

Copy link
Member

@Tobotimus Tobotimus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@calebj This PR adds a lot of really nice things, thank you. Just a few little things that can be fixed up and then I think it's good to go.

loop = asyncio.get_event_loop()

if semaphore is None:
if type(limit) != int or limit <= 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use not isinstance instead of type() !=

try:
done, pending = await asyncio.wait(pending, loop=loop, return_when=FIRST_COMPLETED)
except asyncio.CancelledError:
[]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what's going on with this [] statement, would prefer the use of pass or contextlib.supress

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I had logic here for cancelling pending tasks, but I found something better (see the push)


async def sem_wrapper(sem, task):
async with sem:
return await task
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this sem_wrapper is common to the one in bounded_gather_iter, it can be moved to the module-level and made private

loop = asyncio.get_event_loop()

if semaphore is None:
if type(limit) != int or limit <= 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isinstance here too

@@ -23,6 +23,7 @@
from redbot.core import checks
from redbot.core import i18n
from redbot.core import commands
from redbot.core.cog_manager import NoSuchCog
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import

"""
resolved_paths = _deduplicate(await self.paths())
resolved_paths = deduplicate_iterables(await self.paths())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paths() already deduplicates the paths before it returns, so you can remove the call to deduplicate here

So I went source diving and realized as_completed works the way I want it to,
and I don't need to reinvent the wheel for cancelling tasks that remain
if the generator is `break`ed out of. So there's that.
Copy link
Contributor

@mikeshardmind mikeshardmind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing any issues with this after the changes made. I'm giving it a 👍

@Tobotimus Tobotimus added QA: Passed Used by few QA members. Has been approved by the assigned QA member(s). and removed QA: Needed labels Aug 21, 2018
Copy link
Member

@Tobotimus Tobotimus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Thanks @calebj and thanks @mikeshardmind for reviewing

@Tobotimus Tobotimus merged commit 1329fa1 into Cog-Creators:V3/develop Aug 21, 2018
@calebj calebj deleted the v3/cog_manager_fix_async_utils branch August 21, 2018 01:27
@Jackenmen Jackenmen added Type: Bug Unexpected behavior, result, or exception. In case of PRs, it is a fix for the foregoing. and removed Type: Bug Unexpected behavior, result, or exception. In case of PRs, it is a fix for the foregoing. labels Jul 15, 2021
@Jackenmen Jackenmen added Type: Bug Unexpected behavior, result, or exception. In case of PRs, it is a fix for the foregoing. and removed Type: Fix labels Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
QA: Passed Used by few QA members. Has been approved by the assigned QA member(s). Type: Bug Unexpected behavior, result, or exception. In case of PRs, it is a fix for the foregoing. Type: Enhancement Something meant to enhance existing Red features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants