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

Use deprecated asyncio function depending on Python version #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

raubvogel
Copy link

Description

Select which function in the asyncio library is being used in the Writer class based on the Python version calling duologsync/writer.py.

Motivation and Context

asyncio.get_event_loop() was added in 3.7 and then deprecated in 3.12. Currently it still works but it will cause an error message barking about the deprecation. According to the docs, the replacement is asyncio.run(). In other to avoid breaking it while running in an old version of Python (I was testing against 3.6 and later), I propose to make it use asyncio.get_event_loop() as before while Python < 3.12, and asyncio.run() for Python >= 3.12.

References

How Has This Been Tested?

First tested in a separated script (see below) in a Python virtual environment in Rocky Linux 8.10 against

  • Python 3.6
  • Python 3.9
  • Python 3.12

Have not tested against Python 3.13 yet.

raub@desktop:~/dev/scripts/python$ cat ansyncio_test.py
import asyncio
import sys

async def my_coro():
    return "Result oozes out of your screen"

# Now we select based on Python release
def asyncio_test():
    if sys.version_info >= (3, 12): 
        result = asyncio.run(
            my_coro()  
        )

    else:
        result = asyncio.get_event_loop().run_until_complete(
            my_coro()
        )

    return result

print(sys.version_info)
print(asyncio_test())
raub@desktop:~/dev/scripts/python$

Then tested in the duo_log_sync code, also running inside Python virtual environment against the same Python releases.

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • [x ] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

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.

1 participant