Timeout on subprocess readline in Python

Thanks for all the answers! I found a way to solve my problem by simply using select.poll to peek into standard output. import select … scan_process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) poll_obj = select.poll() poll_obj.register(scan_process.stdout, select.POLLIN) while(some_criterium and not time_limit): poll_result = poll_obj.poll(0) if poll_result: line = scan_process.stdout.readline() some_criterium = do_something(line) update(time_limit)

check output from CalledProcessError

According to the Python os module documentation os.popen has been deprecated since Python 2.6. I think the solution for modern Python is to use check_output() from the subprocess module. From the subprocess Python documentation: subprocess.check_output(args, *, stdin=None, stderr=None, shell=False, universal_newlines=False) Run command with arguments and return its output as a byte string. If the return … Read more

Piping output of subprocess.Popen to files

You can pass stdout and stderr as parameters to Popen() subprocess.Popen(self, args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0) For example >>> import subprocess >>> with open(“stdout.txt”,”wb”) as out, open(“stderr.txt”,”wb”) as err: … subprocess.Popen(“ls”,stdout=out,stderr=err) … <subprocess.Popen object at 0xa3519ec> >>>

Launch IPython notebook with selected browser

I had the same problem on windows and got it work this way: Create a config file with command ipython profile create default Edit ipython_notebook_config.py file, search for line #c.NotebookApp.browser=”” and replace it with import webbrowser webbrowser.register(‘firefox’, None, webbrowser.GenericBrowser(‘C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe’)) c.NotebookApp.browser=”firefox” then it works for me. Hope it will help you. JPG