diff -r 51ac5f06dd04 Lib/webbrowser.py --- a/Lib/webbrowser.py Tue Jul 24 03:45:39 2012 -0700 +++ b/Lib/webbrowser.py Wed Jul 25 14:53:22 2012 +0300 @@ -228,28 +228,32 @@ else: # for TTY browsers, we need stdin/out inout = None - p = subprocess.Popen(cmdline, close_fds=True, stdin=inout, - stdout=(self.redirect_stdout and inout or None), - stderr=inout, start_new_session=True) - if remote: - # wait five seconds. If the subprocess is not finished, the - # remote invocation has (hopefully) started a new instance. - time.sleep(1) - rc = p.poll() - if rc is None: - time.sleep(4) + try: + p = subprocess.Popen(cmdline, close_fds=True, stdin=inout, + stdout=(self.redirect_stdout and inout or None), + stderr=inout, start_new_session=True) + if remote: + # wait five seconds. If the subprocess is not finished, the + # remote invocation has (hopefully) started a new instance. + time.sleep(1) rc = p.poll() if rc is None: + time.sleep(4) + rc = p.poll() + if rc is None: + return True + # if remote call failed, open() will try direct invocation + return not rc + elif self.background: + if p.poll() is None: return True - # if remote call failed, open() will try direct invocation - return not rc - elif self.background: - if p.poll() is None: - return True + else: + return False else: - return False - else: - return not p.wait() + return not p.wait() + finally: + if inout is not None: + inout.close() def open(self, url, new=0, autoraise=True): if new == 0: