Skip to content

Commit

Permalink
examples improved
Browse files Browse the repository at this point in the history
  • Loading branch information
ponty committed Jan 2, 2021
1 parent b6dcb37 commit 3ccf822
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 24 deletions.
54 changes: 44 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,14 @@ print("-- Run program, wait for it to complete, get return code:")
s = EasyProcess([python, "--version"]).call().return_code
print(s)

print("-- Run program, wait 1 second, stop it, get stdout:")
s = EasyProcess(["ping", "localhost"]).start().sleep(1).stop().stdout
print("-- Run program, wait 1.5 second, stop it, get stdout:")
prog = """
import time
for i in range(10):
print(i, flush=True)
time.sleep(1)
"""
s = EasyProcess([python, "-c", prog]).start().sleep(1.5).stop().stdout
print(s)

```
Expand All @@ -89,9 +95,9 @@ $ python3 -m easyprocess.examples.cmd
4
-- Run program, wait for it to complete, get return code:
0
-- Run program, wait 1 second, stop it, get stdout:
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.014 ms
-- Run program, wait 1.5 second, stop it, get stdout:
0
1
```

Shell commands
Expand Down Expand Up @@ -145,10 +151,30 @@ http://docs.python.org/library/threading.html:
```py
# easyprocess/examples/timeout.py

import sys

from easyprocess import EasyProcess

s = EasyProcess(["ping", "localhost"]).call(timeout=2).stdout
print(s)
python = sys.executable

prog = """
import time
for i in range(3):
print(i, flush=True)
time.sleep(1)
"""

print("-- no timeout")
stdout = EasyProcess([python, "-c", prog]).call().stdout
print(stdout)

print("-- timeout=1.5s")
stdout = EasyProcess([python, "-c", prog]).call(timeout=1.5).stdout
print(stdout)

print("-- timeout=50s")
stdout = EasyProcess([python, "-c", prog]).call(timeout=50).stdout
print(stdout)

```

Expand All @@ -158,7 +184,15 @@ Output:

```console
$ python3 -m easyprocess.examples.timeout
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.015 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.023 ms
-- no timeout
0
1
2
-- timeout=1.5s
0
1
-- timeout=50s
0
1
2
```
6 changes: 3 additions & 3 deletions doc/gen/python3_-m_easyprocess.examples.cmd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ $ python3 -m easyprocess.examples.cmd
4
-- Run program, wait for it to complete, get return code:
0
-- Run program, wait 1 second, stop it, get stdout:
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.012 ms
-- Run program, wait 1.5 second, stop it, get stdout:
0
1
14 changes: 11 additions & 3 deletions doc/gen/python3_-m_easyprocess.examples.timeout.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
$ python3 -m easyprocess.examples.timeout
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.013 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.059 ms
-- no timeout
0
1
2
-- timeout=1.5s
0
1
-- timeout=50s
0
1
2
10 changes: 8 additions & 2 deletions easyprocess/examples/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
s = EasyProcess([python, "--version"]).call().return_code
print(s)

print("-- Run program, wait 1 second, stop it, get stdout:")
s = EasyProcess(["ping", "localhost"]).start().sleep(1).stop().stdout
print("-- Run program, wait 1.5 second, stop it, get stdout:")
prog = """
import time
for i in range(10):
print(i, flush=True)
time.sleep(1)
"""
s = EasyProcess([python, "-c", prog]).start().sleep(1.5).stop().stdout
print(s)
24 changes: 22 additions & 2 deletions easyprocess/examples/timeout.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
import sys

from easyprocess import EasyProcess

s = EasyProcess(["ping", "localhost"]).call(timeout=2).stdout
print(s)
python = sys.executable

prog = """
import time
for i in range(3):
print(i, flush=True)
time.sleep(1)
"""

print("-- no timeout")
stdout = EasyProcess([python, "-c", prog]).call().stdout
print(stdout)

print("-- timeout=1.5s")
stdout = EasyProcess([python, "-c", prog]).call(timeout=1.5).stdout
print(stdout)

print("-- timeout=50s")
stdout = EasyProcess([python, "-c", prog]).call(timeout=50).stdout
print(stdout)
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[tox]
envlist =
py39-{tempfile,pipe}
py38
py37
py36
# py3-doc
py38-{tempfile,pipe}
py37-{tempfile,pipe}
py36-{tempfile,pipe}
py3-doc

# Workaround for Vagrant
#toxworkdir={toxinidir}/.tox # default
Expand Down

0 comments on commit 3ccf822

Please sign in to comment.