本文整理汇总了Python中IPython.qt.inprocess.QtInProcessKernelManager.shutdown_kernel方法的典型用法代码示例。如果您正苦于以下问题:Python QtInProcessKernelManager.shutdown_kernel方法的具体用法?Python QtInProcessKernelManager.shutdown_kernel怎么用?Python QtInProcessKernelManager.shutdown_kernel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython.qt.inprocess.QtInProcessKernelManager
的用法示例。
在下文中一共展示了QtInProcessKernelManager.shutdown_kernel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: IPythonView
# 需要导入模块: from IPython.qt.inprocess import QtInProcessKernelManager [as 别名]
# 或者: from IPython.qt.inprocess.QtInProcessKernelManager import shutdown_kernel [as 别名]
class IPythonView(QtGui.QWidget):
def __init__(self, parent=None, getfocus=None):
super(IPythonView, self).__init__(parent)
# Create an in-process kernel
self.kernel_manager = QtInProcessKernelManager()
self.kernel_manager.start_kernel()
self.kernel = self.kernel_manager.kernel
self.kernel.gui = 'qt4'
self.shell = self.kernel.shell
self.kernel_client = self.kernel_manager.client()
self.kernel_client.start_channels()
self.control = RichIPythonWidget()
self.control.set_default_style(colors='linux')
self.control.kernel_manager = self.kernel_manager
self.control.kernel_client = self.kernel_client
self.control.exit_requested.connect(self.stop)
# Enable Pylab mode.
self.shell.enable_pylab()
self.shell.automagic = True
# Add some variables in the namespace.
self.push(galry=galry)
box = QtGui.QVBoxLayout()
box.addWidget(self.control)
box.setContentsMargins(0, 0, 0, 0)
box.setSpacing(0)
self.setLayout(box)
def stop(self, *args):
self.kernel_client.stop_channels()
self.kernel_manager.shutdown_kernel()
# Public methods.
# ---------------
def set_data(self, **kwargs):
self.push(**kwargs)
def push(self, **kwargs):
"""Inject variables in the interactive namespace."""
self.shell.push(kwargs)
def run_file(self, file):
"""Execute a Python file in the interactive namespace."""
self.shell.safe_execfile(file, self.shell.user_global_ns)
def run_cell(self, *args, **kwargs):
"""Execute a cell."""
self.shell.run_cell(*args, **kwargs)
示例2: IPythonConsole
# 需要导入模块: from IPython.qt.inprocess import QtInProcessKernelManager [as 别名]
# 或者: from IPython.qt.inprocess.QtInProcessKernelManager import shutdown_kernel [as 别名]
class IPythonConsole(RichIPythonWidget):
def __init__(self, namespace = dict(), **kwargs):
super(RichIPythonWidget, self).__init__()
self.kernel_manager = QtInProcessKernelManager()
self.kernel_manager.start_kernel()
self.kernel = self.kernel_manager.kernel
self.kernel.gui = 'qt4'
self.kernel.user_ns = namespace
self.kernel.shell.push(kwargs)
self.kernel_client = self.kernel_manager.client()
self.kernel_client.start_channels()
self.exit_requested.connect(self.exit)
def update_namespace(self, **kwargs):
self.kernel.shell.push(kwargs)
def exit(self, *args):
self.kernel_client.stop_channels()
self.kernel_manager.shutdown_kernel()
sys.exit()
示例3: SilverIPython
# 需要导入模块: from IPython.qt.inprocess import QtInProcessKernelManager [as 别名]
# 或者: from IPython.qt.inprocess.QtInProcessKernelManager import shutdown_kernel [as 别名]
class SilverIPython(RichIPythonWidget):
''' Wraps an IPython kernel and provides IPython widgets for it '''
def __init__(self):
RichIPythonWidget.__init__(self)
self.kernel_manager = QtInProcessKernelManager()
self.kernel_manager.start_kernel()
self.kernel = self.kernel_manager.kernel
self.kernel.gui = 'qt4'
self.kernel.shell.push({'window': self, 'kernel': self.kernel})
self.kernel_client = self.kernel_manager.client()
self.kernel_client.start_channels()
self.kernel_client.execute('%pylab inline')
self.exit_requested.connect(self.exit_requested_func)
def send_execute(self, *args,**kwargs):
self.kernel_client.execute( *args,**kwargs )
def exit_requested_func(self):
self.kernel_client.stop_channels()
self.kernel_manager.shutdown_kernel()
qt_app.exit()
示例4: IPythonInProcess
# 需要导入模块: from IPython.qt.inprocess import QtInProcessKernelManager [as 别名]
# 或者: from IPython.qt.inprocess.QtInProcessKernelManager import shutdown_kernel [as 别名]
class IPythonInProcess(object):
def __init__(self,common,customBanner=None):
if customBanner!=None: self.banner=customBanner
self.common = common
self.kernel_manager = None
self.kernel = None
self.control = None
self.kernel_client = None
self.init_qtconsole()
def init_qtconsole(self):
self.main()
def print_process_id(self):
print('Process ID is:', os.getpid())
def main(self):
# Print the ID of the main process
#self.print_process_id()
#app = guisupport.get_app_qt4()
# Create an in-process kernel
# >>> print_process_id()
# will print the same process ID as the main process
self.kernel_manager = QtInProcessKernelManager()
self.kernel_manager.start_kernel()
self.kernel = self.kernel_manager.kernel
self.kernel.gui = 'qt4'
self.kernel.shell.push(self.common.__dict__)
self.kernel_client = self.kernel_manager.client()
self.kernel_client.start_channels()
def stop():
self.kernel_client.stop_channels()
self.kernel_manager.shutdown_kernel()
#app.exit()
self.control = RichIPythonWidget(banner = self.banner)
self.control.kernel_manager = self.kernel_manager
self.control.kernel_client = self.kernel_client
self.control.exit_requested.connect(stop)
#start widget with certain inputs:
#import pylab, which includes all numpy; import pandas as pd
#second argument is whether the execution is hidden e.g. whether a line is used
#I have turned on hide.
self.control._execute('import pylab as pl; import pandas as pd',True)
def SHOW(self):
self.control.show()
#guisupport.start_event_loop_qt4(app)
def pushVariables(self,variableDict):
""" Given a dictionary containing name / value pairs, push those variables to the IPython console widget """
self.kernel_manager.kernel.shell.push(variableDict)
def clearTerminal(self):
""" Clears the terminal """
self._control.clear()
def printText(self,text):
""" Prints some plain text to the console """
self._append_plain_text(text)
def executeCommand(self,command):
""" Execute a command in the frame of the console widget """
self.control._execute(command,False)
示例5: InProcessRunner
# 需要导入模块: from IPython.qt.inprocess import QtInProcessKernelManager [as 别名]
# 或者: from IPython.qt.inprocess.QtInProcessKernelManager import shutdown_kernel [as 别名]
class InProcessRunner(BaseFrontendMixin, QObject):
'''
A runner object that handles running the running tool code via an in-process IPython
kernel. Base off initial runipy code amended to handle in-process running and the IPython FrontendWidget.
'''
# Emitted when a user visible 'execute_request' has been submitted to the
# kernel from the FrontendWidget. Contains the code to be executed.
executing = pyqtSignal(object)
# Emitted when a user-visible 'execute_reply' has been received from the
# kernel and processed by the FrontendWidget. Contains the response message.
executed = pyqtSignal(object)
# Emitted when an exit request has been received from the kernel.
exit_requested = pyqtSignal(object)
# Execute next cell
execute_next = pyqtSignal()
# Emit current cell number
progress = pyqtSignal(object)
_CallTipRequest = namedtuple('_CallTipRequest', ['id', 'pos'])
_CompletionRequest = namedtuple('_CompletionRequest', ['id', 'pos'])
_ExecutionRequest = namedtuple('_ExecutionRequest', ['id', 'kind'])
_local_kernel = False
_hidden = False
MIME_MAP = {
'image/jpeg': 'jpeg',
'image/png': 'png',
'text/plain': 'text',
'text/html': 'html',
'text/latex': 'latex',
'application/javascript': 'html',
'image/svg+xml': 'svg',
}
#---------------------------------------------------------------------------
# 'object' interface
#---------------------------------------------------------------------------
def __init__(self, *args, **kwargs):
super(InProcessRunner, self).__init__(*args, **kwargs)
# FrontendWidget protected variables.
self._kernel_manager = None
self._kernel_client = None
self._request_info = {
'execute': {}
}
self._callback_dict = {}
self._result_queue = []
self._final_msg_id = None
self._cell_execute_ids = {}
self.is_active = False
self.status = STATUS_READY
self._executing = False
# Set flag for whether we are connected via localhost.
self._local_kernel = kwargs.get('local_kernel',
InProcessRunner._local_kernel)
self.kernel_manager = KernelManager()
self.kernel_manager.start_kernel()
self.kernel_client = self.kernel_manager.client()
self.kernel_client.start_channels()
def __del__(self):
if self.kernel_client:
self.kernel_client.stop_channels()
if self.kernel_manager:
self.kernel_manager.shutdown_kernel()
def run(self, tool, varsi, progress_callback=None, result_callback=None):
'''
Run all the cells of a notebook in order and update
the outputs in-place.
'''
self.is_active = True
self.varsi = varsi
self._progress_callback = progress_callback
self._result_callback = result_callback
self._result_queue = [] # Cache for unhandled messages
self._cell_execute_ids = {}
self._execute_start = datetime.now()
self._execute('%reset_selective -f [^_]')
self.kernel_manager.kernel.shell.push({'varsi': varsi})
self._execute(r'''from pathomx.kernel_helpers import pathomx_notebook_start, pathomx_notebook_stop, progress, open_with_progress
pathomx_notebook_start(varsi, vars());''')
setup_languages(self._execute, tool.language)
#.........这里部分代码省略.........
示例6: NotebookRunner
# 需要导入模块: from IPython.qt.inprocess import QtInProcessKernelManager [as 别名]
# 或者: from IPython.qt.inprocess.QtInProcessKernelManager import shutdown_kernel [as 别名]
class NotebookRunner(BaseFrontendMixin, QObject):
'''
A runner object that handles running the running of IPython notebook and working
responses back into the output notebook. Based off the original runipy code
amended to handle in-process running and the IPython FrontendWidget.
'''
# Emitted when a user visible 'execute_request' has been submitted to the
# kernel from the FrontendWidget. Contains the code to be executed.
executing = pyqtSignal(object)
# Emitted when a user-visible 'execute_reply' has been received from the
# kernel and processed by the FrontendWidget. Contains the response message.
executed = pyqtSignal(object)
# Emitted when an exit request has been received from the kernel.
exit_requested = pyqtSignal(object)
# Execute next cell
execute_next = pyqtSignal()
# Emitted when all cells a notebook have been run
notebook_completed = pyqtSignal()
notebook_result = pyqtSignal(object)
# Emit current cell number
progress = pyqtSignal(object)
_CallTipRequest = namedtuple('_CallTipRequest', ['id', 'pos'])
_CompletionRequest = namedtuple('_CompletionRequest', ['id', 'pos'])
_ExecutionRequest = namedtuple('_ExecutionRequest', ['id', 'kind'])
_local_kernel = False
_hidden = False
MIME_MAP = {
'image/jpeg': 'jpeg',
'image/png': 'png',
'text/plain': 'text',
'text/html': 'html',
'text/latex': 'latex',
'application/javascript': 'html',
'image/svg+xml': 'svg',
}
#---------------------------------------------------------------------------
# 'object' interface
#---------------------------------------------------------------------------
def __init__(self, *args, **kwargs):
super(NotebookRunner, self).__init__(*args, **kwargs)
# FrontendWidget protected variables.
self._kernel_manager = None
self._kernel_client = None
self._request_info = {}
self._request_info['execute'] = {};
self._callback_dict = {}
self._result_queue = []
self._final_msg_id = None
self._cell_execute_ids = {}
self._is_active = False
self._executing = False
# Set flag for whether we are connected via localhost.
self._local_kernel = kwargs.get('local_kernel',
NotebookRunner._local_kernel)
self.kernel_manager = KernelManager()
self.kernel_manager.start_kernel()
self.kernel_client = self.kernel_manager.client()
self.kernel_client.start_channels(stdin=False, hb=False)
def __del__(self):
if self.kernel_client:
self.kernel_client.stop_channels()
if self.kernel_manager:
self.kernel_manager.shutdown_kernel()
def iter_code_cells(self):
'''
Iterate over the notebook cells containing code.
'''
for ws in self.nb.worksheets:
for cell in ws.cells:
if cell.cell_type == 'code':
yield cell
def count_code_cells(self):
'''
Return the number of code cells in the notebook
'''
for n, cell in enumerate(self.iter_code_cells()):
pass
return n+1
def run_notebook(self, notebook, varsi, progress_callback=None, result_callback=None):
'''
Run all the cells of a notebook in order and update
#.........这里部分代码省略.........