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

sync scripts: Use asyncio.run instead of get_event_loop #14

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

suutari-ai
Copy link
Member

Replace the asyncio.get_event_loop() followed by run_until_complete(...) call with the asyncio.run(...), because it makes the code cleaner and works even if the event loop in the main thread has been cleared.

This fixes an issue with pytest-asyncio 0.25.2 which seems to clear the main thread event loop sometimes. The tests on sync_attachments and sync_objects used to fail if all tests were ran in the same pytest call, but if only those sync tests are selected (e.g. with pytest -k test_sync) then the tests used to pass. After this change they seem to pass on both cases.

This might be the same issue as described in [1] (even if it is only for Python 3.9, but our issue happens with Python 3.12) or not.

[1] pytest-dev/pytest-asyncio#1039

Replace the asyncio.get_event_loop() followed by run_until_complete(...)
call with the asyncio.run(...), because it makes the code cleaner and
works even if the event loop in the main thread has been cleared.

This fixes an issue with pytest-asyncio 0.25.2 which seems to clear the
main thread event loop sometimes.  The tests on sync_attachments and
sync_objects used to fail if all tests were ran in the same pytest call,
but if only those sync tests are selected (e.g. with `pytest -k
test_sync`) then the tests used to pass.  After this change they seem to
pass on both cases.

This might be the same issue as described in [1] (even if it is only for
Python 3.9, but our issue happens with Python 3.12) or not.

[1] pytest-dev/pytest-asyncio#1039
@suutari-ai suutari-ai requested a review from jopesy January 10, 2025 14:25
@suutari-ai
Copy link
Member Author

This fixes the CI on passari-compose repo, so merging.

@suutari-ai suutari-ai merged commit 14ee29b into master Jan 10, 2025
@suutari-ai suutari-ai deleted the asyncio-run branch January 10, 2025 14:40
Copy link

@jopesy jopesy left a comment

Choose a reason for hiding this comment

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

Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants