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

Combine event loop cleanup with other style/modernization cleanup #4

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
aa31ec4
Remove global `util.main_event_loop`
gnzsnz Aug 15, 2024
56795b3
update github actions, replace flake by ruff
gnzsnz Aug 15, 2024
9c941f1
fix github actions
gnzsnz Aug 15, 2024
0496e6d
upgrade checkout and set-up python actions
gnzsnz Aug 15, 2024
b7b51e6
fix
gnzsnz Aug 15, 2024
b49b2c8
Move to Python 3.10+ and add dev to optional group
mattsta Aug 18, 2024
9dd6f13
Cleanup github CI configuration
mattsta Aug 18, 2024
2ae8bc8
Cleanup coding style for readability
mattsta Aug 18, 2024
7af5787
Fix more event loop fetching
mattsta Aug 18, 2024
775c3ec
Cleanup ruff style complaint
mattsta Aug 18, 2024
a29c3b7
Fix CI error with docs building
mattsta Aug 18, 2024
b80e08c
Fix naming conflict in docs config
mattsta Aug 18, 2024
0dd4ad4
New test for emit_threadsafe
gnzsnz Aug 20, 2024
e8c314d
organize import on event.py, place import before code
gnzsnz Aug 20, 2024
e6faadc
undo event.py imports re-organization as it causes circular dependencies
gnzsnz Aug 20, 2024
eaf4c3f
Modernize Slots management into dataclasses
mattsta Aug 24, 2024
210f48d
add tests for Event.Slot and Event.Slots
gnzsnz Aug 27, 2024
05ee827
use Event._split to build slot
gnzsnz Aug 27, 2024
ccf5325
remove unused import
gnzsnz Aug 27, 2024
68ea189
apply Event._split
gnzsnz Aug 28, 2024
9ecec8d
Implement github actions
gnzsnz Aug 28, 2024
8681633
use eventkit.util.get_event_loop() in tests
gnzsnz Aug 28, 2024
d63441e
Changes
gnzsnz Aug 29, 2024
18e3a4f
remove type hint to avoid mypy error
gnzsnz Aug 29, 2024
fde4203
avoid duplicate execution
gnzsnz Aug 29, 2024
0851e26
add mypy hook to pre-commit
gnzsnz Aug 29, 2024
2bca019
fix error on exception handling during emit/slots.__call__
gnzsnz Sep 1, 2024
5628f9f
pre-
gnzsnz Sep 6, 2024
09cf836
pypy support for weakref tests
gnzsnz Sep 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix more event loop fetching
Primarily due to version changes over time, this all used to work in
older versions, but Python 3.12 started issuing new warnings and errors
unless manual steps are used for event loop handling instead of automatic steps.

Fixes #2
  • Loading branch information
mattsta committed Aug 18, 2024
commit 7af5787a2c0c7e929c4457cd87f424e2ca431685
14 changes: 12 additions & 2 deletions eventkit/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio
import datetime as dt
import functools

from typing import AsyncIterator


@@ -16,9 +18,17 @@ def __repr__(self):
NO_VALUE = _NoValue()


@functools.cache
def get_event_loop():
"""Get asyncio event loop, running or not."""
return asyncio.get_event_loop_policy().get_event_loop()
"""Get asyncio event loop or create one if it doesn't exist."""
try:
# https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_running_loop
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

return loop


async def timerange(start=0, end=None, step: float = 1) -> AsyncIterator[dt.datetime]:
3 changes: 1 addition & 2 deletions tests/create_test.py
Original file line number Diff line number Diff line change
@@ -6,11 +6,10 @@
array1 = list(range(10))
array2 = list(range(100, 110))

loop = asyncio.get_event_loop_policy().get_event_loop()


class CreateTest(unittest.TestCase):
def test_wait(self):
loop = asyncio.get_event_loop_policy().get_event_loop()
fut = asyncio.Future(loop=loop)
loop.call_later(0.001, fut.set_result, 42)
event = Event.wait(fut)
6 changes: 4 additions & 2 deletions tests/event_test.py
Original file line number Diff line number Diff line change
@@ -4,8 +4,10 @@
import eventkit as ev
from eventkit import Event

loop = asyncio.get_event_loop_policy().get_event_loop()
run = loop.run_until_complete

def run(*args, **kwargs):
loop = asyncio.get_event_loop_policy().get_event_loop()
return loop.run_until_complete(*args, **kwargs)


class Object:
3 changes: 0 additions & 3 deletions tests/transform_test.py
Original file line number Diff line number Diff line change
@@ -6,9 +6,6 @@

from eventkit import Event

loop = asyncio.get_event_loop_policy().get_event_loop()
loop.set_debug(True)

array = list(range(20))