Skip to content

Commit

Permalink
Add Proactor version of priority loop
Browse files Browse the repository at this point in the history
  • Loading branch information
kristjanvalur committed Dec 9, 2023
1 parent ae52c66 commit acb7687
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/asynkit/experimental/priority.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import contextlib
import random
import sys
import weakref
from abc import ABC, abstractmethod
from asyncio import Handle, Lock, Task
Expand Down Expand Up @@ -684,3 +685,17 @@ def __init__(self, arg: Any = None) -> None:
super().__init__(arg)
self.init()
self._ready = self.ready_queue


DefaultPriorityEventLoop = PrioritySelectorEventLoop

if hasattr(asyncio, "ProactorEventLoop"): # pragma: no coverage

class PriorityProactorEventLoop(asyncio.ProactorEventLoop, PrioritySchedulingMixin):
def __init__(self, arg: Any = None) -> None:
super().__init__(arg)
self.init()
self._ready = self.ready_queue

if sys.platform == "win32": # pragma: no coverage
DefaultPriorityEventLoop = PriorityProactorEventLoop # type: ignore
6 changes: 3 additions & 3 deletions tests/experimental/test_priority.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
PosPriorityQueue,
PriorityCondition,
PriorityLock,
PrioritySelectorEventLoop,
DefaultPriorityEventLoop,
PriorityTask,
)

Expand Down Expand Up @@ -621,7 +621,7 @@ def __init__(self, request):
self.request = request

def new_event_loop(self):
return PrioritySelectorEventLoop()
return DefaultPriorityEventLoop()


class TestPriorityScheduling:
Expand All @@ -638,7 +638,7 @@ async def nothing():

async def test_create_event_loop(self):
loop = asyncio.get_running_loop()
assert isinstance(loop, PrioritySelectorEventLoop)
assert isinstance(loop, DefaultPriorityEventLoop)
assert loop._ready is loop.ready_queue

async def test_simple_task(self):
Expand Down

0 comments on commit acb7687

Please sign in to comment.