From 7c25d09be04a2979bcfb43b801de57594112808d Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 21 Aug 2023 15:37:22 -0500 Subject: [PATCH] revert the rename of push and pop methods choose the way that is compatible with 8.x and 9.x --- asyncio/core.py | 16 ++++++++-------- asyncio/event.py | 4 ++-- asyncio/funcs.py | 2 +- asyncio/lock.py | 6 +++--- asyncio/task.py | 4 ++++ 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/asyncio/core.py b/asyncio/core.py index 524cc57..e31c1ce 100644 --- a/asyncio/core.py +++ b/asyncio/core.py @@ -62,7 +62,7 @@ def __await__(self): def __next__(self): if self.state is not None: - _task_queue.push(cur_task, self.state) + _task_queue.push_sorted(cur_task, self.state) self.state = None return None else: @@ -179,11 +179,11 @@ def wait_io_event(self, dt): # print('poll', s, sm, ev) if ev & ~select.POLLOUT and sm[0] is not None: # POLLIN or error - _task_queue.push(sm[0]) + _task_queue.push_head(sm[0]) sm[0] = None if ev & ~select.POLLIN and sm[1] is not None: # POLLOUT or error - _task_queue.push(sm[1]) + _task_queue.push_head(sm[1]) sm[1] = None if sm[0] is None and sm[1] is None: self._dequeue(s) @@ -211,7 +211,7 @@ def create_task(coro): if not hasattr(coro, "send"): raise TypeError("coroutine expected") t = Task(coro, globals()) - _task_queue.push(t) + _task_queue.push_head(t) return t @@ -238,7 +238,7 @@ def run_until_complete(main_task=None): _io_queue.wait_io_event(dt) # Get next task to run and continue it - t = _task_queue.pop() + t = _task_queue.pop_head() cur_task = t try: # Continue running the coroutine, it's responsible for rescheduling itself @@ -274,7 +274,7 @@ def run_until_complete(main_task=None): else: # Schedule any other tasks waiting on the completion of this task. while t.state.peek(): - _task_queue.push(t.state.pop()) + _task_queue.push_head(t.state.pop_head()) waiting = True # "False" indicates that the task is complete and has been await'ed on. t.state = False @@ -282,7 +282,7 @@ def run_until_complete(main_task=None): # An exception ended this detached task, so queue it for later # execution to handle the uncaught exception if no other task retrieves # the exception in the meantime (this is handled by Task.throw). - _task_queue.push(t) + _task_queue.push_head(t) # Save return value of coro to pass up to caller. t.data = er elif t.state is None: @@ -344,7 +344,7 @@ def stop(): global _stop_task if _stop_task is not None: - _task_queue.push(_stop_task) + _task_queue.push_head(_stop_task) # If stop() is called again, do nothing _stop_task = None diff --git a/asyncio/event.py b/asyncio/event.py index 5e1cb24..a402d26 100644 --- a/asyncio/event.py +++ b/asyncio/event.py @@ -40,7 +40,7 @@ def set(self): # Note: This must not be called from anything except the thread running # the asyncio loop (i.e. neither hard or soft IRQ, or a different thread). while self.waiting.peek(): - core._task_queue.push(self.waiting.pop()) + core._task_queue.push_head(self.waiting.pop_head()) self.state = True def clear(self): @@ -57,7 +57,7 @@ async def wait(self): if not self.state: # Event not set, put the calling task on the event's waiting queue - self.waiting.push(core.cur_task) + self.waiting.push_head(core.cur_task) # Set calling task's data to the event's queue so it can be removed if needed core.cur_task.data = self.waiting await core._never() diff --git a/asyncio/funcs.py b/asyncio/funcs.py index dc27088..baf804d 100644 --- a/asyncio/funcs.py +++ b/asyncio/funcs.py @@ -116,7 +116,7 @@ def done(t, er): # Still some sub-tasks running. return # Gather waiting is done, schedule the main gather task. - core._task_queue.push(gather_task) + core._task_queue.push_head(gather_task) ts = [core._promote_to_task(aw) for aw in aws] for i in range(len(ts)): diff --git a/asyncio/lock.py b/asyncio/lock.py index c9feb35..71c972f 100644 --- a/asyncio/lock.py +++ b/asyncio/lock.py @@ -50,8 +50,8 @@ def release(self): raise RuntimeError("Lock not acquired") if self.waiting.peek(): # Task(s) waiting on lock, schedule next Task - self.state = self.waiting.pop() - core._task_queue.push(self.state) + self.state = self.waiting.pop_head() + core._task_queue.push_head(self.state) else: # No Task waiting so unlock self.state = 0 @@ -65,7 +65,7 @@ async def acquire(self): if self.state != 0: # Lock unavailable, put the calling Task on the waiting queue - self.waiting.push(core.cur_task) + self.waiting.push_head(core.cur_task) # Set calling task's data to the lock's queue so it can be removed if needed core.cur_task.data = self.waiting try: diff --git a/asyncio/task.py b/asyncio/task.py index c1306d0..2e3a6db 100644 --- a/asyncio/task.py +++ b/asyncio/task.py @@ -130,6 +130,10 @@ def pop(self): def remove(self, v): self.heap = ph_delete(self.heap, v) + # Compatibility aliases, remove after they are no longer used + push_head = push + push_sorted = push + pop_head = pop # Task class representing a coroutine, can be waited on and cancelled. class Task: