mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	Issue #26848: Fix asyncio/subprocess.communicate() to handle empty input.
This commit is contained in:
		
							parent
							
								
									d76c7c2bed
								
							
						
					
					
						commit
						7657f6ba21
					
				
					 3 changed files with 23 additions and 1 deletions
				
			
		|  | @ -166,7 +166,7 @@ def _read_stream(self, fd): | |||
| 
 | ||||
|     @coroutine | ||||
|     def communicate(self, input=None): | ||||
|         if input: | ||||
|         if input is not None: | ||||
|             stdin = self._feed_stdin(input) | ||||
|         else: | ||||
|             stdin = self._noop() | ||||
|  |  | |||
|  | @ -287,6 +287,25 @@ def len_message(message): | |||
|         self.assertEqual(output.rstrip(), b'3') | ||||
|         self.assertEqual(exitcode, 0) | ||||
| 
 | ||||
|     def test_empty_input(self): | ||||
|         @asyncio.coroutine | ||||
|         def empty_input(): | ||||
|             code = 'import sys; data = sys.stdin.read(); print(len(data))' | ||||
|             proc = yield from asyncio.create_subprocess_exec( | ||||
|                                           sys.executable, '-c', code, | ||||
|                                           stdin=asyncio.subprocess.PIPE, | ||||
|                                           stdout=asyncio.subprocess.PIPE, | ||||
|                                           stderr=asyncio.subprocess.PIPE, | ||||
|                                           close_fds=False, | ||||
|                                           loop=self.loop) | ||||
|             stdout, stderr = yield from proc.communicate(b'') | ||||
|             exitcode = yield from proc.wait() | ||||
|             return (stdout, exitcode) | ||||
| 
 | ||||
|         output, exitcode = self.loop.run_until_complete(empty_input()) | ||||
|         self.assertEqual(output.rstrip(), b'0') | ||||
|         self.assertEqual(exitcode, 0) | ||||
| 
 | ||||
|     def test_cancel_process_wait(self): | ||||
|         # Issue #23140: cancel Process.wait() | ||||
| 
 | ||||
|  |  | |||
|  | @ -436,6 +436,9 @@ Library | |||
| - Issue #26406: Avoid unnecessary serialization of getaddrinfo(3) calls on | ||||
|   current versions of OpenBSD and NetBSD.  Patch by A. Jesse Jiryu Davis. | ||||
| 
 | ||||
| - Issue #26848: Fix asyncio/subprocess.communicate() to handle empty input. | ||||
|   Patch by Jack O'Connor. | ||||
| 
 | ||||
| Documentation | ||||
| ------------- | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yury Selivanov
						Yury Selivanov