Skip to content

Commit

Permalink
revert the rename of push and pop methods
Browse files Browse the repository at this point in the history
choose the way that is compatible with 8.x and 9.x
  • Loading branch information
jepler committed Aug 21, 2023
1 parent 510d4a3 commit 7c25d09
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
16 changes: 8 additions & 8 deletions asyncio/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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


Expand All @@ -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
Expand Down Expand Up @@ -274,15 +274,15 @@ 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
if not waiting and not isinstance(er, excs_stop):
# 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:
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions asyncio/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion asyncio/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down
6 changes: 3 additions & 3 deletions asyncio/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions asyncio/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7c25d09

Please sign in to comment.