mirror of https://github.com/flaggo/pydu.git
Merge branch 'master' into master
This commit is contained in:
commit
0406da62eb
|
@ -83,7 +83,7 @@ File
|
|||
|
||||
.. py:function:: pydu.file.touch(path):
|
||||
|
||||
open a file as write,and then close it.
|
||||
Open a file as write,and then close it.
|
||||
|
||||
>>> from pydu.file import touch
|
||||
>>> touch('test.txt')
|
||||
|
@ -105,8 +105,3 @@ File
|
|||
|
||||
>>> from pydu.file import link
|
||||
>>> link('test.txt','test.link')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
16
pydu/cmd.py
16
pydu/cmd.py
|
@ -11,16 +11,14 @@ def run(cmd, wait=True, shell=True, timeout=0, timeinterval=1):
|
|||
if not wait:
|
||||
return p
|
||||
|
||||
if not timeout:
|
||||
stdout, _ = p.communicate()
|
||||
return p.poll(), stdout
|
||||
if timeout:
|
||||
while timeout > 0 and p.poll() is None:
|
||||
timeout = timeout - timeinterval
|
||||
time.sleep(timeinterval)
|
||||
if p.poll() is None:
|
||||
p.kill()
|
||||
return p.poll(), 'Run timeout'
|
||||
|
||||
while timeout > 0 and p.poll() is None:
|
||||
timeout = timeout - timeinterval
|
||||
time.sleep(timeinterval)
|
||||
if p.poll() is None:
|
||||
p.kill()
|
||||
return p.poll(), 'Run timeout'
|
||||
stdout, _ = p.communicate()
|
||||
return p.poll(), stdout
|
||||
|
||||
|
|
|
@ -41,6 +41,6 @@ def _is_ip(ip, af):
|
|||
def get_free_port():
|
||||
s = socket.socket(socket.AF_INET, type=socket.SOCK_STREAM)
|
||||
s.bind(('127.0.0.1', 0))
|
||||
address, port = s.getsockname()
|
||||
_, port = s.getsockname()
|
||||
s.close()
|
||||
return port
|
||||
|
|
Loading…
Reference in New Issue