Use communicate() to avoid subprocess hanging.
This commit is contained in:
@@ -7,6 +7,7 @@ import time
|
|||||||
import codecs
|
import codecs
|
||||||
import curses
|
import curses
|
||||||
import logging
|
import logging
|
||||||
|
import threading
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import subprocess
|
import subprocess
|
||||||
import curses.ascii
|
import curses.ascii
|
||||||
@@ -369,11 +370,10 @@ class Terminal(object):
|
|||||||
p = subprocess.Popen(
|
p = subprocess.Popen(
|
||||||
[command], stderr=subprocess.PIPE,
|
[command], stderr=subprocess.PIPE,
|
||||||
universal_newlines=True, shell=True)
|
universal_newlines=True, shell=True)
|
||||||
code = p.wait()
|
_, stderr = p.communicate()
|
||||||
if copious_output:
|
if copious_output:
|
||||||
six.moves.input('Press any key to continue')
|
six.moves.input('Press any key to continue')
|
||||||
if code != 0:
|
if p.poll() != 0:
|
||||||
_, stderr = p.communicate()
|
|
||||||
_logger.warning(stderr)
|
_logger.warning(stderr)
|
||||||
self.show_notification(
|
self.show_notification(
|
||||||
'Program exited with status={0}\n{1}'.format(
|
'Program exited with status={0}\n{1}'.format(
|
||||||
@@ -396,6 +396,13 @@ class Terminal(object):
|
|||||||
'Program exited with status={0}\n{1}'.format(
|
'Program exited with status={0}\n{1}'.format(
|
||||||
code, stderr.strip()))
|
code, stderr.strip()))
|
||||||
|
|
||||||
|
# Spin off a thread with p.communicate() to avoid subprocess
|
||||||
|
# hang when the stodout/stderr PIPE gets filled up. This
|
||||||
|
# behavior was discovered when opening long gifs with mpv
|
||||||
|
# because mpv sends a progress bar to stderr.
|
||||||
|
# https://thraxil.org/users/anders/posts/2008/03/13/
|
||||||
|
threading.Thread(target=p.communicate).start()
|
||||||
|
|
||||||
def get_mailcap_entry(self, url):
|
def get_mailcap_entry(self, url):
|
||||||
"""
|
"""
|
||||||
Search through the mime handlers list and attempt to find the
|
Search through the mime handlers list and attempt to find the
|
||||||
@@ -519,10 +526,8 @@ class Terminal(object):
|
|||||||
try:
|
try:
|
||||||
with self.suspend():
|
with self.suspend():
|
||||||
p = subprocess.Popen([pager], stdin=subprocess.PIPE)
|
p = subprocess.Popen([pager], stdin=subprocess.PIPE)
|
||||||
p.stdin.write(data.encode('utf-8'))
|
|
||||||
p.stdin.close()
|
|
||||||
try:
|
try:
|
||||||
p.wait()
|
p.communicate(data.encode('utf-8'))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
p.terminate()
|
p.terminate()
|
||||||
except OSError:
|
except OSError:
|
||||||
@@ -560,7 +565,7 @@ class Terminal(object):
|
|||||||
with self.suspend():
|
with self.suspend():
|
||||||
p = subprocess.Popen([editor, filepath])
|
p = subprocess.Popen([editor, filepath])
|
||||||
try:
|
try:
|
||||||
p.wait()
|
p.communicate()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
p.terminate()
|
p.terminate()
|
||||||
except OSError:
|
except OSError:
|
||||||
|
|||||||
Reference in New Issue
Block a user