本文整理汇总了Python中spyderlib.qt.QtCore.QProcess.readAllStandardError方法的典型用法代码示例。如果您正苦于以下问题:Python QProcess.readAllStandardError方法的具体用法?Python QProcess.readAllStandardError怎么用?Python QProcess.readAllStandardError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spyderlib.qt.QtCore.QProcess
的用法示例。
在下文中一共展示了QProcess.readAllStandardError方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProfilerWidget
# 需要导入模块: from spyderlib.qt.QtCore import QProcess [as 别名]
# 或者: from spyderlib.qt.QtCore.QProcess import readAllStandardError [as 别名]
#.........这里部分代码省略.........
self.datelabel.setText(_('Profiling, please wait...'))
self.process = QProcess(self)
self.process.setProcessChannelMode(QProcess.SeparateChannels)
self.process.setWorkingDirectory(wdir)
self.connect(self.process, SIGNAL("readyReadStandardOutput()"),
self.read_output)
self.connect(self.process, SIGNAL("readyReadStandardError()"),
lambda: self.read_output(error=True))
self.connect(self.process,
SIGNAL("finished(int,QProcess::ExitStatus)"),
self.finished)
self.connect(self.stop_button, SIGNAL("clicked()"), self.process.kill)
if pythonpath is not None:
env = [to_text_string(_pth)
for _pth in self.process.systemEnvironment()]
baseshell.add_pathlist_to_PYTHONPATH(env, pythonpath)
self.process.setEnvironment(env)
self.output = ''
self.error_output = ''
p_args = ['-m', 'cProfile', '-o', self.DATAPATH]
if os.name == 'nt':
# On Windows, one has to replace backslashes by slashes to avoid
# confusion with escape characters (otherwise, for example, '\t'
# will be interpreted as a tabulation):
p_args.append(osp.normpath(filename).replace(os.sep, '/'))
else:
p_args.append(filename)
if args:
p_args.extend(shell_split(args))
executable = sys.executable
if executable.endswith("spyder.exe"):
# py2exe distribution
executable = "python.exe"
self.process.start(executable, p_args)
running = self.process.waitForStarted()
self.set_running_state(running)
if not running:
QMessageBox.critical(self, _("Error"),
_("Process failed to start"))
def set_running_state(self, state=True):
self.start_button.setEnabled(not state)
self.stop_button.setEnabled(state)
def read_output(self, error=False):
if error:
self.process.setReadChannel(QProcess.StandardError)
else:
self.process.setReadChannel(QProcess.StandardOutput)
qba = QByteArray()
while self.process.bytesAvailable():
if error:
qba += self.process.readAllStandardError()
else:
qba += self.process.readAllStandardOutput()
text = to_text_string( locale_codec.toUnicode(qba.data()) )
if error:
self.error_output += text
else:
self.output += text
def finished(self):
self.set_running_state(False)
self.show_errorlog() # If errors occurred, show them.
self.output = self.error_output + self.output
# FIXME: figure out if show_data should be called here or
# as a signal from the combobox
self.show_data(justanalyzed=True)
def kill_if_running(self):
if self.process is not None:
if self.process.state() == QProcess.Running:
self.process.kill()
self.process.waitForFinished()
def show_data(self, justanalyzed=False):
if not justanalyzed:
self.output = None
self.log_button.setEnabled(self.output is not None \
and len(self.output) > 0)
self.kill_if_running()
filename = to_text_string(self.filecombo.currentText())
if not filename:
return
self.datatree.load_data(self.DATAPATH)
self.datelabel.setText(_('Sorting data, please wait...'))
QApplication.processEvents()
self.datatree.show_tree()
text_style = "<span style=\'color: #444444\'><b>%s </b></span>"
date_text = text_style % time.strftime("%d %b %Y %H:%M",
time.localtime())
self.datelabel.setText(date_text)
示例2: PluginClient
# 需要导入模块: from spyderlib.qt.QtCore import QProcess [as 别名]
# 或者: from spyderlib.qt.QtCore.QProcess import readAllStandardError [as 别名]
class PluginClient(QObject):
"""
A class which handles a connection to a plugin through a QProcess.
"""
# Emitted when the plugin has initialized.
initialized = Signal()
# Emitted when the plugin has failed to load.
errored = Signal()
# Emitted when a request response is received.
request_handled = Signal(object)
def __init__(self, plugin_name, executable=None):
super(PluginClient, self).__init__()
self.plugin_name = plugin_name
self.executable = executable or sys.executable
self.start()
def start(self):
"""Start a new connection with the plugin.
"""
self._initialized = False
plugin_name = self.plugin_name
self.sock, server_port = connect_to_port()
self.sock.listen(2)
QApplication.instance().aboutToQuit.connect(self.close)
self.process = QProcess(self)
self.process.setWorkingDirectory(os.path.dirname(__file__))
processEnvironment = QProcessEnvironment()
env = self.process.systemEnvironment()
python_path = imp.find_module('spyderlib')[1]
# Use the current version of the plugin provider if possible.
try:
provider_path = imp.find_module(self.plugin_name)[1]
python_path = os.sep.join([python_path, provider_path])
except ImportError:
pass
env.append("PYTHONPATH=%s" % python_path)
for envItem in env:
envName, separator, envValue = envItem.partition('=')
processEnvironment.insert(envName, envValue)
self.process.setProcessEnvironment(processEnvironment)
p_args = ['-u', 'plugin_server.py', str(server_port), plugin_name]
self.listener = PluginListener(self.sock)
self.listener.request_handled.connect(self.request_handled.emit)
self.listener.initialized.connect(self._on_initialized)
self.listener.start()
self.process.start(self.executable, p_args)
self.process.finished.connect(self._on_finished)
running = self.process.waitForStarted()
if not running:
raise IOError('Could not start plugin %s' % plugin_name)
def send(self, request):
"""Send a request to the plugin.
"""
if not self._initialized:
return
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("127.0.0.1", self.client_port))
request['plugin_name'] = self.plugin_name
write_packet(sock, request)
sock.close()
def close(self):
self.process.kill()
self.process.waitForFinished(200)
self.sock.close()
def _on_initialized(self, port):
debug_print('Initialized %s' % self.plugin_name)
self._initialized = True
self.client_port = port
self.initialized.emit()
def _on_finished(self):
debug_print('finished %s %s' % (self.plugin_name, self._initialized))
if self._initialized:
self.start()
else:
self._initialized = False
debug_print(self.process.readAllStandardOutput())
debug_print(self.process.readAllStandardError())
self.errored.emit()
示例3: PylintWidget
# 需要导入模块: from spyderlib.qt.QtCore import QProcess [as 别名]
# 或者: from spyderlib.qt.QtCore.QProcess import readAllStandardError [as 别名]
#.........这里部分代码省略.........
plver = PYLINT_VER
if plver is not None:
if plver.split('.')[0] == '0':
p_args = ['-i', 'yes']
else:
# Option '-i' (alias for '--include-ids') was removed in pylint
# 1.0
p_args = ["--msg-template='{msg_id}:{line:3d},"\
"{column}: {obj}: {msg}"]
p_args += [osp.basename(filename)]
else:
p_args = [osp.basename(filename)]
self.process.start(PYLINT_PATH, p_args)
running = self.process.waitForStarted()
self.set_running_state(running)
if not running:
QMessageBox.critical(self, _("Error"),
_("Process failed to start"))
def set_running_state(self, state=True):
self.start_button.setEnabled(not state)
self.stop_button.setEnabled(state)
def read_output(self, error=False):
if error:
self.process.setReadChannel(QProcess.StandardError)
else:
self.process.setReadChannel(QProcess.StandardOutput)
qba = QByteArray()
while self.process.bytesAvailable():
if error:
qba += self.process.readAllStandardError()
else:
qba += self.process.readAllStandardOutput()
text = to_text_string( locale_codec.toUnicode(qba.data()) )
if error:
self.error_output += text
else:
self.output += text
def finished(self, exit_code, exit_status):
self.set_running_state(False)
if not self.output:
if self.error_output:
QMessageBox.critical(self, _("Error"), self.error_output)
print("pylint error:\n\n" + self.error_output, file=sys.stderr)
return
# Convention, Refactor, Warning, Error
results = {'C:': [], 'R:': [], 'W:': [], 'E:': []}
txt_module = '************* Module '
module = '' # Should not be needed - just in case something goes wrong
for line in self.output.splitlines():
if line.startswith(txt_module):
# New module
module = line[len(txt_module):]
continue
# Supporting option include-ids: ('R3873:' instead of 'R:')
if not re.match('^[CRWE]+([0-9]{4})?:', line):
continue
i1 = line.find(':')
if i1 == -1:
continue
示例4: AsyncClient
# 需要导入模块: from spyderlib.qt.QtCore import QProcess [as 别名]
# 或者: from spyderlib.qt.QtCore.QProcess import readAllStandardError [as 别名]
#.........这里部分代码省略.........
if (self.env and 'PYTHONPATH' not in self.env) or DEV:
python_path = osp.dirname(get_module_path('spyderlib'))
# Add the libs to the python path.
for lib in self.libs:
try:
path = osp.dirname(imp.find_module(lib)[1])
python_path = osp.pathsep.join([python_path, path])
except ImportError:
pass
env.append("PYTHONPATH=%s" % python_path)
if self.env:
env.update(self.env)
for envItem in env:
envName, separator, envValue = envItem.partition('=')
processEnvironment.insert(envName, envValue)
self.process.setProcessEnvironment(processEnvironment)
# Start the process and wait for started.
self.process.start(self.executable, p_args)
self.process.finished.connect(self._on_finished)
running = self.process.waitForStarted()
if not running:
raise IOError('Could not start %s' % self)
# Set up the socket notifer.
fid = self.socket.getsockopt(zmq.FD)
self.notifier = QSocketNotifier(fid, QSocketNotifier.Read, self)
self.notifier.activated.connect(self._on_msg_received)
def request(self, func_name, *args, **kwargs):
"""Send a request to the server.
The response will be a dictionary the 'request_id' and the
'func_name' as well as a 'result' field with the object returned by
the function call or or an 'error' field with a traceback.
"""
if not self.is_initialized:
return
request_id = uuid.uuid4().hex
request = dict(func_name=func_name,
args=args,
kwargs=kwargs,
request_id=request_id)
try:
self.socket.send_pyobj(request)
except zmq.ZMQError:
pass
return request_id
def close(self):
"""Cleanly close the connection to the server.
"""
self.closing = True
self.timer.stop()
self.request('server_quit')
self.process.waitForFinished(1000)
self.context.destroy(0)
def _on_finished(self):
"""Handle a finished signal from the process.
"""
if self.closing:
return
if self.is_initialized:
debug_print('Restarting %s' % self.name)
debug_print(self.process.readAllStandardOutput())
debug_print(self.process.readAllStandardError())
self.is_initialized = False
self.notifier.setEnabled(False)
self.run()
else:
debug_print('Errored %s' % self.name)
debug_print(self.process.readAllStandardOutput())
debug_print(self.process.readAllStandardError())
self.errored.emit()
def _on_msg_received(self):
"""Handle a message trigger from the socket.
"""
self.notifier.setEnabled(False)
while 1:
try:
resp = self.socket.recv_pyobj(flags=zmq.NOBLOCK)
except zmq.ZMQError:
self.notifier.setEnabled(True)
return
if not self.is_initialized:
self.is_initialized = True
debug_print('Initialized %s' % self.name)
self.initialized.emit()
continue
resp['name'] = self.name
self.received.emit(resp)
def _heartbeat(self):
"""Send a heartbeat to keep the server alive.
"""
if not self.is_initialized:
return
self.socket.send_pyobj(dict(func_name='server_heartbeat'))