8000 Refuse handlers if the child watcher has no loop attached by vxgmichel · Pull Request #391 · python/asyncio · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Refuse handlers if the child watcher has no loop attached #391

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Ignore or catch warnings from f7a5259 in the tests
  • Loading branch information
Vincent Michel c 8000 ommitted Aug 2, 2016
commit 9ab616879f5e2d2548d3005460bee248289dcbf1
4 changes: 4 additions & 0 deletions tests/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ def kill_running():
# the transport was not notified yet
self.assertFalse(killed)

# Clear the handlers for FastChildWatcher to avoid a warning.
# Is that a bug?
asyncio.get_child_watcher()._callbacks.clear()

def test_popen_error(self):
# Issue #24763: check that the subprocess transport is closed
# when BaseSubprocessTransport fails
Expand Down
7 changes: 6 additions & 1 deletion tests/test_unix_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import tempfile
import threading
import unittest
import warnings
from unittest import mock

if sys.platform == 'win32':
Expand Down Expand Up @@ -1396,7 +1397,11 @@ def test_set_loop_race_condition(self, m):
with mock.patch.object(
old_loop, "remove_signal_handler") as m_remove_signal_handler:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using with self.assertWarnsRegexp?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, it's much cleaner now!

self.watcher.attach_loop(None)
with warnings.catch_warnings(record=True) as warns:
self.watcher.attach_loop(None)
self.assertEqual(len(warns), 1)
self.assertEqual(warns[0].category, RuntimeWarning)
self.assertIn('A loop is being detached', warns[0].message.args[0])

m_remove_signal_handler.assert_called_once_with(
signal.SIGCHLD)
Expand Down
0