1
1
import asyncio
2
2
import contextlib
3
3
import signal
4
- import socket
5
4
import subprocess
6
5
import sys
7
6
import tempfile
8
- import uvloop
9
7
10
8
from asyncio import test_utils
11
9
from uvloop import _testbase as tb
12
- from test import support
13
10
14
11
15
12
class _TestProcess :
@@ -276,12 +273,12 @@ def test_stdin_not_inheritable(self):
276
273
def len_message (message ):
277
274
code = 'import sys; data = sys.stdin.read(); print(len(data))'
278
275
proc = yield from asyncio .create_subprocess_exec (
279
- sys .executable , '-c' , code ,
280
- stdin = asyncio .subprocess .PIPE ,
281
- stdout = asyncio .subprocess .PIPE ,
282
- stderr = asyncio .subprocess .PIPE ,
283
- close_fds = False ,
284
- loop = self .loop )
276
+ sys .executable , '-c' , code ,
277
+ stdin = asyncio .subprocess .PIPE ,
278
+ stdout = asyncio .subprocess .PIPE ,
279
+ stderr = asyncio .subprocess .PIPE ,
280
+ close_fds = False ,
281
+ loop = self .loop )
285
282
stdout , stderr = yield from proc .communicate (message )
286
283
exitcode = yield from proc .wait ()
287
284
return (stdout , exitcode )
@@ -296,10 +293,10 @@ def test_stdin_stdout(self):
296
293
@asyncio .coroutine
297
294
def run (data ):
298
295
proc = yield from asyncio .create_subprocess_exec (
299
- * args ,
300
- stdin = subprocess .PIPE ,
301
- stdout = subprocess .PIPE ,
302
- loop = self .loop )
296
+ * args ,
297
+ stdin = subprocess .PIPE ,
298
+ stdout = subprocess .PIPE ,
299
+ loop = self .loop )
303
300
304
301
# feed data
305
302
proc .stdin .write (data )
@@ -323,10 +320,10 @@ def test_communicate(self):
323
320
@asyncio .coroutine
324
321
def run (data ):
325
322
proc = yield from asyncio .create_subprocess_exec (
326
- * args ,
327
- stdin = subprocess .PIPE ,
328
- stdout = subprocess .PIPE ,
329
- loop = self .loop )
323
+ * args ,
324
+ stdin = subprocess .PIPE ,
325
+ stdout = subprocess .PIPE ,
326
+ loop = self .loop )
330
327
stdout , stderr = yield from proc .communicate (data )
331
328
return proc .returncode , stdout
332
329
@@ -389,35 +386,14 @@ def send_signal(proc):
389
386
returncode = self .loop .run_until_complete (send_signal (proc ))
390
387
self .assertEqual (- signal .SIGHUP , returncode )
391
388
392
- def test_stdin_not_inheritable (self ):
393
- # asyncio issue #209: stdin must not be inheritable, otherwise
394
- # the Process.communicate() hangs
395
- @asyncio .coroutine
396
- def len_message (message ):
397
- code = 'import sys; data = sys.stdin.read(); print(len(data))'
398
- proc = yield from asyncio .create_subprocess_exec (
399
- sys .executable , '-c' , code ,
400
- stdin = asyncio .subprocess .PIPE ,
401
- stdout = asyncio .subprocess .PIPE ,
402
- stderr = asyncio .subprocess .PIPE ,
403
- close_fds = False ,
404
- loop = self .loop )
405
- stdout , stderr = yield from proc .communicate (message )
406
- exitcode = yield from proc .wait ()
407
- return (stdout , exitcode )
408
-
409
- output , exitcode = self .loop .run_until_complete (len_message (b'abc' ))
410
- self .assertEqual (output .rstrip (), b'3' )
411
- self .assertEqual (exitcode , 0 )
412
-
413
389
def test_cancel_process_wait (self ):
414
390
# Issue #23140: cancel Process.wait()
415
391
416
392
@asyncio .coroutine
417
393
def cancel_wait ():
418
394
proc = yield from asyncio .create_subprocess_exec (
419
- * self .PROGRAM_BLOCKED ,
420
- loop = self .loop )
395
+ * self .PROGRAM_BLOCKED ,
396
+ loop = self .loop )
421
397
422
398
# Create an internal future waiting on the process exit
423
399
task = self .loop .create_task (proc .wait ())
0 commit comments