Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ def create_task(self, coro, *, name=None):
else:
task = self._task_factory(self, coro)
tasks._set_task_name(task, name)
self._write_to_self()

return task

Expand Down Expand Up @@ -595,6 +596,7 @@ def stop(self):
Every callback already scheduled will still run. This simply informs
run_forever to stop looping after a complete iteration.
"""
self._write_to_self()
self._stopping = True

def close(self):
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_asyncio/test_base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def cb(arg):
calls.append(arg)

self.loop._process_events = mock.Mock()
self.loop._write_to_self = mock.Mock()
self.loop.call_later(-1, cb, 'a')
self.loop.call_later(-2, cb, 'b')
test_utils.run_briefly(self.loop)
Expand All @@ -265,6 +266,7 @@ def cb():
self.loop.stop()

self.loop._process_events = mock.Mock()
self.loop._write_to_self = mock.Mock()
delay = 0.1

when = self.loop.time() + delay
Expand Down Expand Up @@ -486,6 +488,7 @@ def throw():
raise ShowStopper

self.loop._process_events = mock.Mock()
self.loop._write_to_self = mock.Mock()
self.loop.call_soon(throw)
try:
self.loop.run_until_complete(foo(0.1))
Expand Down Expand Up @@ -547,6 +550,7 @@ def test_subprocess_shell_invalid_args(self):

def test_default_exc_handler_callback(self):
self.loop._process_events = mock.Mock()
self.loop._write_to_self = mock.Mock()

def zero_error(fut):
fut.set_result(True)
Expand Down Expand Up @@ -574,6 +578,7 @@ def zero_error(fut):

def test_default_exc_handler_coro(self):
self.loop._process_events = mock.Mock()
self.loop._write_to_self = mock.Mock()

@asyncio.coroutine
def zero_error_coro():
Expand Down Expand Up @@ -719,6 +724,7 @@ def test_set_task_factory_invalid(self):

def test_set_task_factory(self):
self.loop._process_events = mock.Mock()
self.loop._write_to_self = mock.Mock()

class MyTask(asyncio.Task):
pass
Expand Down Expand Up @@ -835,6 +841,7 @@ def raise_keyboard_interrupt():
raise KeyboardInterrupt

self.loop._process_events = mock.Mock()
self.loop._write_to_self = mock.Mock()
self.loop.call_exception_handler = mock.Mock()

try:
Expand All @@ -854,6 +861,7 @@ def raise_keyboard_interrupt():
raise KeyboardInterrupt

self.loop._process_events = mock.Mock()
self.loop._write_to_self = mock.Mock()

try:
self.loop.run_until_complete(raise_keyboard_interrupt())
Expand Down Expand Up @@ -894,6 +902,7 @@ def clear_selector():

self.loop._process_events = proc_events
self.loop._selector.select.return_value = (event_sentinel,)
self.loop._write_to_self = mock.Mock()

for i in range(1, 3):
with self.subTest('Loop %d/2' % i):
Expand All @@ -913,13 +922,15 @@ def callback():
count += 1

self.loop._process_events = mock.Mock()
self.loop._write_to_self = mock.Mock()
self.loop.call_soon(callback)
test_utils.run_once(self.loop)
self.assertEqual(count, 1)

def test_run_forever_pre_stopped(self):
# Test that the old idiom for pre-stopping the loop works.
self.loop._process_events = mock.Mock()
self.loop._write_to_self = mock.Mock()
self.loop.stop()
self.loop.run_forever()
self.loop._selector.select.assert_called_once_with(0)
Expand Down Expand Up @@ -1860,6 +1871,7 @@ def simple_coroutine():

@mock.patch('asyncio.base_events.logger')
def test_log_slow_callbacks(self, m_logger):
self.loop._write_to_self = mock.Mock()
def stop_loop_cb(loop):
loop.stop()

Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_asyncio/test_pep492.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def setUp(self):
self.loop._process_events = mock.Mock()
self.loop._selector = mock.Mock()
self.loop._selector.select.return_value = ()
self.loop._write_to_self = mock.Mock()
self.set_event_loop(self.loop)


Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_asyncio/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async def shutdown_asyncgens():
loop.shutdown_ag_run = True
loop.shutdown_asyncgens = shutdown_asyncgens

loop._write_to_self = mock.Mock()
return loop

def setUp(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wake up loop