Python 3 showing progressbar while subprocess.Popen

Have an interesting case I want to share and save for future. One small problem in this system: https://github.com/trianglesis/BMC_TPL_IDE is showing when some process is running and was not hanged up. Sometimes we need to run a huge amount of checks and tests and would be great to know if something hangs before killing it mannually. I used different scenarios and mostly a module pregressbar2, and this is what I finally can compose: Make worker which will execute job sorf of randomly: import time import random print(“START SOMETHING”) for i in range(5): sec = random.randint(1, 3) print(“Sleeping for: %d” % sec) time.sleep(sec) print(“Making job, line: %d” % i) print(“END SOMETHING”) Make process executor: import sys import subprocess import progressbar # DrawShort Read more…

Python Run External Command And Get Output On Screen or In Variable

Отседова: http://www.cyberciti.biz/faq/python-run-external-command-and-get-output/ The basic syntax is: import subprocess subprocess.call(“command-name-here”) subprocess.call([“/path/to/command”, “arg1”, “-arg2”]) Run ping command to send ICMP ECHO_REQUEST packets to www.cyberciti.biz: #!/usr/bin/python import subprocess subprocess.call([“ping”, “-c 2”, “www.cyberciti.biz”]) Свой вариант: C:\Python34>python.exe Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32 Type “help”, “copyright”, “credits” or “license” for more information. >>> import subprocess >>> subprocess.call([“ping”, “-t”, “8.8.8.8”]) Pinging 8.8.8.8 with 32 bytes of data: Reply from 8.8.8.8: bytes=32 time=49ms TTL=43 Reply from 8.8.8.8: bytes=32 time=42ms TTL=43 Reply from 8.8.8.8: bytes=32 time=42ms TTL=43 Reply from 8.8.8.8: bytes=32 time=42ms TTL=43 Reply from 8.8.8.8: bytes=32 time=43ms TTL=43 Reply from 8.8.8.8: bytes=32 time=42ms TTL=43 Reply from 8.8.8.8: bytes=32 time=42ms TTL=43 Reply from 8.8.8.8: bytes=32 time=42ms TTL=43 Ping statistics forShort Read more…