@@ -62,7 +62,7 @@ def __await__(self):
6262
6363 def __next__ (self ):
6464 if self .state is not None :
65- _task_queue .push (cur_task , self .state )
65+ _task_queue .push_sorted (cur_task , self .state )
6666 self .state = None
6767 return None
6868 else :
@@ -179,11 +179,11 @@ def wait_io_event(self, dt):
179179 # print('poll', s, sm, ev)
180180 if ev & ~ select .POLLOUT and sm [0 ] is not None :
181181 # POLLIN or error
182- _task_queue .push (sm [0 ])
182+ _task_queue .push_head (sm [0 ])
183183 sm [0 ] = None
184184 if ev & ~ select .POLLIN and sm [1 ] is not None :
185185 # POLLOUT or error
186- _task_queue .push (sm [1 ])
186+ _task_queue .push_head (sm [1 ])
187187 sm [1 ] = None
188188 if sm [0 ] is None and sm [1 ] is None :
189189 self ._dequeue (s )
@@ -211,7 +211,7 @@ def create_task(coro):
211211 if not hasattr (coro , "send" ):
212212 raise TypeError ("coroutine expected" )
213213 t = Task (coro , globals ())
214- _task_queue .push (t )
214+ _task_queue .push_head (t )
215215 return t
216216
217217
@@ -238,7 +238,7 @@ def run_until_complete(main_task=None):
238238 _io_queue .wait_io_event (dt )
239239
240240 # Get next task to run and continue it
241- t = _task_queue .pop ()
241+ t = _task_queue .pop_head ()
242242 cur_task = t
243243 try :
244244 # Continue running the coroutine, it's responsible for rescheduling itself
@@ -274,15 +274,15 @@ def run_until_complete(main_task=None):
274274 else :
275275 # Schedule any other tasks waiting on the completion of this task.
276276 while t .state .peek ():
277- _task_queue .push (t .state .pop ())
277+ _task_queue .push_head (t .state .pop_head ())
278278 waiting = True
279279 # "False" indicates that the task is complete and has been await'ed on.
280280 t .state = False
281281 if not waiting and not isinstance (er , excs_stop ):
282282 # An exception ended this detached task, so queue it for later
283283 # execution to handle the uncaught exception if no other task retrieves
284284 # the exception in the meantime (this is handled by Task.throw).
285- _task_queue .push (t )
285+ _task_queue .push_head (t )
286286 # Save return value of coro to pass up to caller.
287287 t .data = er
288288 elif t .state is None :
@@ -344,7 +344,7 @@ def stop():
344344
345345 global _stop_task
346346 if _stop_task is not None :
347- _task_queue .push (_stop_task )
347+ _task_queue .push_head (_stop_task )
348348 # If stop() is called again, do nothing
349349 _stop_task = None
350350
0 commit comments