Merge branch 'master' into master

This commit is contained in:
Prodesire 2017-12-11 22:59:51 +08:00 committed by GitHub
commit 0406da62eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 16 deletions

View File

@ -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')

View File

@ -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

View File

@ -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