mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	bpo-35621: Support running subprocesses in asyncio when loop is executed in non-main thread (#13630)
This commit is contained in:
		
							parent
							
								
									c52996785a
								
							
						
					
					
						commit
						13ed07998a
					
				
					 4 changed files with 262 additions and 54 deletions
				
			
		|  | @ -1082,6 +1082,8 @@ def test_not_implemented(self): | |||
|             NotImplementedError, watcher.attach_loop, f) | ||||
|         self.assertRaises( | ||||
|             NotImplementedError, watcher.close) | ||||
|         self.assertRaises( | ||||
|             NotImplementedError, watcher.is_active) | ||||
|         self.assertRaises( | ||||
|             NotImplementedError, watcher.__enter__) | ||||
|         self.assertRaises( | ||||
|  | @ -1784,15 +1786,6 @@ def test_close(self, m): | |||
|                 if isinstance(self.watcher, asyncio.FastChildWatcher): | ||||
|                     self.assertFalse(self.watcher._zombies) | ||||
| 
 | ||||
|     @waitpid_mocks | ||||
|     def test_add_child_handler_with_no_loop_attached(self, m): | ||||
|         callback = mock.Mock() | ||||
|         with self.create_watcher() as watcher: | ||||
|             with self.assertRaisesRegex( | ||||
|                     RuntimeError, | ||||
|                     'the child watcher does not have a loop attached'): | ||||
|                 watcher.add_child_handler(100, callback) | ||||
| 
 | ||||
| 
 | ||||
| class SafeChildWatcherTests (ChildWatcherTestsMixin, test_utils.TestCase): | ||||
|     def create_watcher(self): | ||||
|  | @ -1809,17 +1802,16 @@ class PolicyTests(unittest.TestCase): | |||
|     def create_policy(self): | ||||
|         return asyncio.DefaultEventLoopPolicy() | ||||
| 
 | ||||
|     def test_get_child_watcher(self): | ||||
|     def test_get_default_child_watcher(self): | ||||
|         policy = self.create_policy() | ||||
|         self.assertIsNone(policy._watcher) | ||||
| 
 | ||||
|         watcher = policy.get_child_watcher() | ||||
|         self.assertIsInstance(watcher, asyncio.SafeChildWatcher) | ||||
|         self.assertIsInstance(watcher, asyncio.ThreadedChildWatcher) | ||||
| 
 | ||||
|         self.assertIs(policy._watcher, watcher) | ||||
| 
 | ||||
|         self.assertIs(watcher, policy.get_child_watcher()) | ||||
|         self.assertIsNone(watcher._loop) | ||||
| 
 | ||||
|     def test_get_child_watcher_after_set(self): | ||||
|         policy = self.create_policy() | ||||
|  | @ -1829,18 +1821,6 @@ def test_get_child_watcher_after_set(self): | |||
|         self.assertIs(policy._watcher, watcher) | ||||
|         self.assertIs(watcher, policy.get_child_watcher()) | ||||
| 
 | ||||
|     def test_get_child_watcher_with_mainloop_existing(self): | ||||
|         policy = self.create_policy() | ||||
|         loop = policy.get_event_loop() | ||||
| 
 | ||||
|         self.assertIsNone(policy._watcher) | ||||
|         watcher = policy.get_child_watcher() | ||||
| 
 | ||||
|         self.assertIsInstance(watcher, asyncio.SafeChildWatcher) | ||||
|         self.assertIs(watcher._loop, loop) | ||||
| 
 | ||||
|         loop.close() | ||||
| 
 | ||||
|     def test_get_child_watcher_thread(self): | ||||
| 
 | ||||
|         def f(): | ||||
|  | @ -1865,7 +1845,11 @@ def test_child_watcher_replace_mainloop_existing(self): | |||
|         policy = self.create_policy() | ||||
|         loop = policy.get_event_loop() | ||||
| 
 | ||||
|         watcher = policy.get_child_watcher() | ||||
|         # Explicitly setup SafeChildWatcher, | ||||
|         # default ThreadedChildWatcher has no _loop property | ||||
|         watcher = asyncio.SafeChildWatcher() | ||||
|         policy.set_child_watcher(watcher) | ||||
|         watcher.attach_loop(loop) | ||||
| 
 | ||||
|         self.assertIs(watcher._loop, loop) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andrew Svetlov
						Andrew Svetlov