Skip to content

Commit 01396e6

Browse files
author
Jonathan Rocher
committed
Adding an interesting subprocess demo and the poll method of a child process.
1 parent f5f385f commit 01396e6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
""" Demo creating a subprocess and doing something in the master process when
2+
the child is running. To know about the child's state we demo the poll method of
3+
the process.
4+
"""
5+
6+
from subprocess import Popen
7+
import sys
8+
print "Starting..."
9+
# sleep for 10 seconds
10+
p = Popen(['sleep','10'])
11+
# continue on with processing
12+
print "Continuing",
13+
k=0
14+
while p.poll() is None:
15+
k += 1
16+
if (k % 100000) == 0:
17+
print k//100000,
18+
sys.stdout.flush()
19+
print
20+
print "Done", p.returncode

0 commit comments

Comments
 (0)