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

fix: Update async utils to remove upcoming deprecated call #6297

Merged
merged 1 commit into from
Nov 18, 2023

Conversation

lucashuy
Copy link
Contributor

@lucashuy lucashuy commented Nov 17, 2023

Which issue(s) does this change fix?

None.

Why is this change necessary?

asyncio.get_event_loop() is being deprecated in the future. Deprecation warns are starting to appear, which will cause tests to fail since warnings are treated as errors.

How does it address the issue?

Removes the call to asyncio.get_event_loop() as a default value for the tasks.

What side effects does this change have?

None.

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@lucashuy lucashuy marked this pull request as ready for review November 17, 2023 18:21
@lucashuy lucashuy requested a review from a team as a code owner November 17, 2023 18:21

LOG = logging.getLogger(__name__)


async def _run_given_tasks_async(tasks, event_loop=asyncio.get_event_loop(), executor=None):
async def _run_given_tasks_async(
tasks: List[Callable], event_loop: AbstractEventLoop, executor: Optional[ThreadPoolExecutor] = None
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we use the default value at all?

Copy link
Contributor Author

@lucashuy lucashuy Nov 17, 2023

Choose a reason for hiding this comment

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

No, since the creation of this util the event loop was always specified and the helper methods are only called within this file:

event_loop = asyncio.new_event_loop()
if not default_executor:
with ThreadPoolExecutor() as self.executor:
return run_given_tasks_async(self._async_tasks, event_loop, self.executor)
return run_given_tasks_async(self._async_tasks, event_loop)

@@ -111,7 +116,7 @@ def add_async_task(self, function, *args):
"""
self._async_tasks.append(partial(function, *args))

def run_async(self, default_executor=True):
def run_async(self, default_executor: bool = True) -> list:
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding type definitions!

@lucashuy lucashuy added this pull request to the merge queue Nov 18, 2023
Merged via the queue into aws:develop with commit 074785f Nov 18, 2023
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants