diff --git a/docs/file.rst b/docs/file.rst index 06cc547..79e7652 100644 --- a/docs/file.rst +++ b/docs/file.rst @@ -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') - - - - - diff --git a/pydu/cmd.py b/pydu/cmd.py index 195ab46..e01f5db 100644 --- a/pydu/cmd.py +++ b/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 diff --git a/pydu/network.py b/pydu/network.py index 8eb70bd..b9efb56 100644 --- a/pydu/network.py +++ b/pydu/network.py @@ -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