Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
ff8a701
drop in apply_request handler in zmq.ipkernel
minrk Mar 23, 2012
09cd42a
lazy-formatting logs in ipkernel
minrk Mar 23, 2012
1901b79
allow multiple shell_sockets in ipkernel
minrk Mar 23, 2012
1587a7f
allow aborting tasks
minrk Mar 23, 2012
fbf9e2e
respect copy flag in Session.recv
minrk Mar 24, 2012
d362026
Don't copy shell requests
minrk Mar 24, 2012
ed57daf
move apply serialization into zmq.serialize
minrk Mar 24, 2012
6174cb0
add ids to ipkernel
minrk Mar 24, 2012
9440f9e
use IOLoop in ipkernel
minrk Mar 24, 2012
24fdfb1
use IPython.zmq.kernel in parallel Engines
minrk Mar 24, 2012
5c5118d
allow exceptions in handlers without crashing
minrk Mar 24, 2012
7f6086f
use execute_request for parallel execute, instead of apply
minrk Mar 24, 2012
08b95f8
scrub: ident on iopub
minrk Mar 24, 2012
ccd2ca4
enable topics on IOPub messages
minrk Mar 24, 2012
02449c1
use shell namespaces in apply_request
minrk Mar 24, 2012
c6717a5
don't abort queue on execution failure
minrk Mar 24, 2012
716157f
avoid passing code objects to execute, now that execute uses code-as-…
minrk Mar 24, 2012
f9d7005
fixup shutdown/exit now that we use IOLoop
minrk Mar 24, 2012
3724f43
remove now-obsolete kernel fork used in engine
minrk Mar 24, 2012
cfdfd64
don't use history files in Engines
minrk Mar 25, 2012
99269af
add silent kwarg to run_cell
minrk Mar 28, 2012
de14aa1
use new run_cell(silent=True) instead of run_code in ipkernel
minrk Mar 28, 2012
c5c7935
do not use ZMQStream for IOPub
minrk Apr 19, 2012
2f3f0c8
remove disused pykernel
minrk Apr 19, 2012
4048621
remove references to removed pykernel and associated pure flag
minrk Apr 23, 2012
5cc602b
fix subheaders for execute_reply and aborted messages
minrk Apr 24, 2012
3531213
test resubmit of aborted tasks (#1647)
minrk Apr 24, 2012
4cda2dc
fix Kernel import in engineapp
minrk May 8, 2012
d8f08af
fix kernel_argv in qtconsole
minrk May 8, 2012
788c738
expose silent in view.execute
minrk May 8, 2012
60c884a
track display data in the parallel Client
minrk May 8, 2012
a27adad
discard parallel.util.asbytes in favor of py3compat.cast_bytes
minrk May 9, 2012
e0899e5
fix topic on displayhook in ZMQShell
minrk May 12, 2012
e7f402a
fix message when trying new table due to mismatch in SQLiteDB
minrk May 12, 2012
4e5eb7d
soften messages for monitor messages with bad topics
minrk May 12, 2012
fa181ff
resubmitted tasks are now wholly separate (new msg_ids)
minrk May 12, 2012
3c9c367
remove old _really_apply call
minrk May 13, 2012
6423e9d
store execute_replies in a nice wrapper
minrk May 13, 2012
d34fb7b
minor fixes to allow kernel to be re-entrant
minrk May 15, 2012
f56f5a1
upstream change preventing kernel exit on SIGINT during eventloop int…
minrk May 15, 2012
13736b9
InteractiveShell.restore_sys_module_state actually restores main
minrk May 15, 2012
ea917e3
test re-entrant embed_kernel
minrk May 15, 2012
0d0437b
undo initial clobbering done by init_sys_modules in embed_kernel
minrk May 15, 2012
176eff9
add @interactive decorator to IPython.parallel namespace
minrk May 15, 2012
05f0cd8
add len(view)
minrk May 15, 2012
cf52d06
add topic to display publisher, and fix set_parent for apply_requests
minrk May 15, 2012
1805e53
test new execute/output behaviors
minrk May 15, 2012
efa86d9
clearer error when trying to use closed Client
minrk May 22, 2012
04351cd
Don't use asserts when checking for connection files
minrk May 22, 2012
4cb7712
fix date objects in _reserialize_reply
minrk May 22, 2012
4afa366
disable save-thread when using in-memory history db.
minrk May 22, 2012
ea84367
fix run_cell signature in parallelmagic
minrk May 22, 2012
e4f5c29
expose kernel at app-level, so EngineApp looks like KernelApp
minrk May 22, 2012
e9a0b8e
check for any Application with Kernel in zmq.eventloop
minrk May 22, 2012
7576fb6
test %pylab on engines
minrk May 22, 2012
85e05e1
demote enter/exit eventloop messages to INFO
minrk May 22, 2012
d2f71ea
move default log setup to _log_default from init_logging
minrk May 22, 2012
9fc6597
Application.log_format is a configurable
minrk May 22, 2012
f24fe97
split init_sockets into a few steps, so they can be better reused
minrk May 22, 2012
3b1700a
reduce parentless IOPub message to warning level
minrk May 22, 2012
23d0ff7
add listen_kernel method to IPEngineApp
minrk May 22, 2012
83b4b12
allow embed_kernel to be called from engine
minrk May 22, 2012
3fab994
kernel app cleans up connection files that it wrote
minrk May 22, 2012
100a5e3
relax some timing constraints in parallel tests
minrk May 22, 2012
46db02d
store whole content, instead of just display data in metadata.outputs
minrk May 23, 2012
e0b0d5e
revert embed_kernel changes that implied bind_kernel in engine
minrk May 23, 2012
64f2f8d
add IPython.parallel.bind_kernel
minrk May 23, 2012
45a4d04
use [sys.exe, "-c", "…launch_new_instance()"] in launchers
minrk May 23, 2012
87af741
switch order of failed-to-start errors in test_embed_kernel
minrk May 25, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions IPython/config/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,30 @@ def _log_level_changed(self, name, old, new):
new = getattr(logging, new)
self.log_level = new
self.log.setLevel(new)

log_format = Unicode("[%(name)s] %(message)s", config=True,
help="The Logging format template",
)
log = Instance(logging.Logger)
def _log_default(self):
"""Start logging for this application.

The default is to log to stdout using a StreaHandler. The log level
starts at loggin.WARN, but this can be adjusted by setting the
``log_level`` attribute.
"""
log = logging.getLogger(self.__class__.__name__)
log.setLevel(self.log_level)
if sys.executable.endswith('pythonw.exe'):
# this should really go to a file, but file-logging is only
# hooked up in parallel applications
_log_handler = logging.StreamHandler(open(os.devnull, 'w'))
else:
_log_handler = logging.StreamHandler()
_log_formatter = logging.Formatter(self.log_format)
_log_handler.setFormatter(_log_formatter)
log.addHandler(_log_handler)
return log

# the alias map for configurables
aliases = Dict({'log-level' : 'Application.log_level'})
Expand Down Expand Up @@ -169,32 +193,11 @@ def __init__(self, **kwargs):
if self.__class__ not in self.classes:
self.classes.insert(0, self.__class__)

self.init_logging()

def _config_changed(self, name, old, new):
SingletonConfigurable._config_changed(self, name, old, new)
self.log.debug('Config changed:')
self.log.debug(repr(new))

def init_logging(self):
"""Start logging for this application.

The default is to log to stdout using a StreaHandler. The log level
starts at loggin.WARN, but this can be adjusted by setting the
``log_level`` attribute.
"""
self.log = logging.getLogger(self.__class__.__name__)
self.log.setLevel(self.log_level)
if sys.executable.endswith('pythonw.exe'):
# this should really go to a file, but file-logging is only
# hooked up in parallel applications
self._log_handler = logging.StreamHandler(open(os.devnull, 'w'))
else:
self._log_handler = logging.StreamHandler()
self._log_formatter = logging.Formatter("[%(name)s] %(message)s")
self._log_handler.setFormatter(self._log_formatter)
self.log.addHandler(self._log_handler)

@catch_config_error
def initialize(self, argv=None):
"""Do the basic steps to configure me.
Expand Down
5 changes: 3 additions & 2 deletions IPython/core/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,9 @@ def __init__(self, shell=None, config=None, **traits):
self.save_flag = threading.Event()
self.db_input_cache_lock = threading.Lock()
self.db_output_cache_lock = threading.Lock()
self.save_thread = HistorySavingThread(self)
self.save_thread.start()
if self.hist_file != ':memory:':
self.save_thread = HistorySavingThread(self)
self.save_thread.start()

self.new_session()

Expand Down
28 changes: 20 additions & 8 deletions IPython/core/interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ def save_sys_module_state(self):
self._orig_sys_module_state['stderr'] = sys.stderr
self._orig_sys_module_state['excepthook'] = sys.excepthook
self._orig_sys_modules_main_name = self.user_module.__name__
self._orig_sys_modules_main_mod = sys.modules.get(self.user_module.__name__)

def restore_sys_module_state(self):
"""Restore the state of the sys module."""
Expand All @@ -726,7 +727,8 @@ def restore_sys_module_state(self):
except AttributeError:
pass
# Reset what what done in self.init_sys_modules
sys.modules[self.user_module.__name__] = self._orig_sys_modules_main_name
if self._orig_sys_modules_main_mod is not None:
sys.modules[self._orig_sys_modules_main_name] = self._orig_sys_modules_main_mod

#-------------------------------------------------------------------------
# Things related to hooks
Expand Down Expand Up @@ -2429,7 +2431,7 @@ def safe_run_module(self, mod_name, where):
self.showtraceback()
warn('Unknown failure executing module: <%s>' % mod_name)

def run_cell(self, raw_cell, store_history=False):
def run_cell(self, raw_cell, store_history=False, silent=False):
"""Run a complete IPython cell.

Parameters
Expand All @@ -2440,9 +2442,15 @@ def run_cell(self, raw_cell, store_history=False):
If True, the raw and translated cell will be stored in IPython's
history. For user code calling back into IPython's machinery, this
should be set to False.
silent : bool
If True, avoid side-effets, such as implicit displayhooks, history,
and logging. silent=True forces store_history=False.
"""
if (not raw_cell) or raw_cell.isspace():
return

if silent:
store_history = False

for line in raw_cell.splitlines():
self.input_splitter.push(line)
Expand All @@ -2467,8 +2475,8 @@ def run_cell(self, raw_cell, store_history=False):
if store_history:
self.history_manager.store_inputs(self.execution_count,
cell, raw_cell)

self.logger.log(cell, raw_cell)
if not silent:
self.logger.log(cell, raw_cell)

if not prefilter_failed:
# don't run if prefilter failed
Expand All @@ -2488,12 +2496,16 @@ def run_cell(self, raw_cell, store_history=False):
if store_history:
self.execution_count += 1
return None


interactivity = "none" if silent else "last_expr"
self.run_ast_nodes(code_ast.body, cell_name,
interactivity="last_expr")

interactivity=interactivity)
# Execute any registered post-execution functions.
for func, status in self._post_execute.iteritems():
# unless we are silent
post_exec = [] if silent else self._post_execute.iteritems()

for func, status in post_exec:
if self.disable_failing_post_execute and not status:
continue
try:
Expand Down
55 changes: 55 additions & 0 deletions IPython/core/tests/test_interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,61 @@ def test_bad_var_expand(self):
self.assertEqual(ip.var_expand(u"{asdf}"), u"{asdf}")
# ZeroDivisionError
self.assertEqual(ip.var_expand(u"{1/0}"), u"{1/0}")

def test_silent_nopostexec(self):
"""run_cell(silent=True) doesn't invoke post-exec funcs"""
ip = get_ipython()

d = dict(called=False)
def set_called():
d['called'] = True

ip.register_post_execute(set_called)
ip.run_cell("1", silent=True)
self.assertFalse(d['called'])
# double-check that non-silent exec did what we expected
# silent to avoid
ip.run_cell("1")
self.assertTrue(d['called'])
# remove post-exec
ip._post_execute.pop(set_called)

def test_silent_noadvance(self):
"""run_cell(silent=True) doesn't advance execution_count"""
ip = get_ipython()

ec = ip.execution_count
# silent should force store_history=False
ip.run_cell("1", store_history=True, silent=True)

self.assertEquals(ec, ip.execution_count)
# double-check that non-silent exec did what we expected
# silent to avoid
ip.run_cell("1", store_history=True)
self.assertEquals(ec+1, ip.execution_count)

def test_silent_nodisplayhook(self):
"""run_cell(silent=True) doesn't trigger displayhook"""
ip = get_ipython()

d = dict(called=False)

trap = ip.display_trap
save_hook = trap.hook

def failing_hook(*args, **kwargs):
d['called'] = True

try:
trap.hook = failing_hook
ip.run_cell("1", silent=True)
self.assertFalse(d['called'])
# double-check that non-silent exec did what we expected
# silent to avoid
ip.run_cell("1")
self.assertTrue(d['called'])
finally:
trap.hook = save_hook

@skipif(sys.version_info[0] >= 3, "softspace removed in py3")
def test_print_softspace(self):
Expand Down
4 changes: 2 additions & 2 deletions IPython/extensions/parallelmagic.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def _maybe_display_output(self, result):
print '[stdout:%i]'%eid, stdout


def pxrun_cell(self, raw_cell, store_history=True):
def pxrun_cell(self, raw_cell, store_history=False, silent=False):
"""drop-in replacement for InteractiveShell.run_cell.

This executes code remotely, instead of in the local namespace.
Expand Down Expand Up @@ -258,7 +258,7 @@ def pxrun_cell(self, raw_cell, store_history=True):
return False
else:
try:
result = self.active_view.execute(cell, block=False)
result = self.active_view.execute(cell, silent=False, block=False)
except:
ipself.showtraceback()
return True
Expand Down
6 changes: 1 addition & 5 deletions IPython/frontend/consoleapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ class IPythonConsoleApp(Configurable):
frontend_flags = Any(app_flags)
frontend_aliases = Any(app_aliases)

pure = CBool(False, config=True,
help="Use a pure Python kernel instead of an IPython kernel.")
# create requested profiles by default, if they don't exist:
auto_create = CBool(True)
# connection info:
Expand Down Expand Up @@ -330,9 +328,7 @@ def init_kernel_manager(self):
)
# start the kernel
if not self.existing:
kwargs = dict(ipython=not self.pure)
kwargs['extra_arguments'] = self.kernel_argv
self.kernel_manager.start_kernel(**kwargs)
self.kernel_manager.start_kernel(extra_arguments=self.kernel_argv)
elif self.sshserver:
# ssh, write new connection file
self.kernel_manager.write_connection_file()
Expand Down
2 changes: 0 additions & 2 deletions IPython/frontend/html/notebook/clustermanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class DummyIPClusterStart(IPClusterStart):

def init_signal(self):
pass
def init_logging(self):
pass
def reinit_logging(self):
pass

Expand Down
7 changes: 4 additions & 3 deletions IPython/frontend/html/notebook/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from IPython.external.decorator import decorator
from IPython.zmq.session import Session
from IPython.lib.security import passwd_check
from IPython.utils.jsonutil import date_default

try:
from docutils.core import publish_string
Expand Down Expand Up @@ -385,13 +386,13 @@ def _reserialize_reply(self, msg_list):
except KeyError:
pass
msg.pop('buffers')
return jsonapi.dumps(msg)
return jsonapi.dumps(msg, default=date_default)

def _on_zmq_reply(self, msg_list):
try:
msg = self._reserialize_reply(msg_list)
except:
self.application.log.critical("Malformed message: %r" % msg_list)
except Exception:
self.application.log.critical("Malformed message: %r" % msg_list, exc_info=True)
else:
self.write_message(msg)

Expand Down
2 changes: 1 addition & 1 deletion IPython/frontend/html/notebook/notebookapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ def init_configurables(self):
self.cluster_manager.update_profiles()

def init_logging(self):
super(NotebookApp, self).init_logging()
# This prevents double log messages because tornado use a root logger that
# self.log is a child of. The logging module dipatches log messages to a log
# and all of its ancenstors until propagate is set to False.
Expand Down Expand Up @@ -493,6 +492,7 @@ def _signal_stop(self, sig, frame):

@catch_config_error
def initialize(self, argv=None):
self.init_logging()
super(NotebookApp, self).initialize(argv)
self.init_configurables()
self.init_webapp()
Expand Down
22 changes: 6 additions & 16 deletions IPython/frontend/qt/console/qtconsoleapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ def gui_excepthook(exctype, value, tb):
# start with copy of flags
flags = dict(flags)
qt_flags = {
'pure' : ({'IPythonQtConsoleApp' : {'pure' : True}},
"Use a pure Python kernel instead of an IPython kernel."),
'plain' : ({'ConsoleWidget' : {'kind' : 'plain'}},
'plain' : ({'IPythonQtConsoleApp' : {'plain' : True}},
"Disable rich text support."),
}
qt_flags.update(boolean_flag(
Expand Down Expand Up @@ -180,18 +178,14 @@ class IPythonQtConsoleApp(BaseIPythonApplication, IPythonConsoleApp):
plain = CBool(False, config=True,
help="Use a plaintext widget instead of rich text (plain can't print/save).")

def _pure_changed(self, name, old, new):
kind = 'plain' if self.plain else 'rich'
def _plain_changed(self, name, old, new):
kind = 'plain' if new else 'rich'
self.config.ConsoleWidget.kind = kind
if self.pure:
self.widget_factory = FrontendWidget
elif self.plain:
if new:
self.widget_factory = IPythonWidget
else:
self.widget_factory = RichIPythonWidget

_plain_changed = _pure_changed

# the factory for creating a widget
widget_factory = Any(RichIPythonWidget)

Expand All @@ -210,7 +204,7 @@ def new_frontend_master(self):
config=self.config,
)
# start the kernel
kwargs = dict(ipython=not self.pure)
kwargs = dict()
kwargs['extra_arguments'] = self.kernel_argv
kernel_manager.start_kernel(**kwargs)
kernel_manager.start_channels()
Expand Down Expand Up @@ -273,17 +267,13 @@ def init_qt_elements(self):
self.window.add_tab_with_frontend(self.widget)
self.window.init_menu_bar()

self.window.setWindowTitle('Python' if self.pure else 'IPython')
self.window.setWindowTitle('IPython')

def init_colors(self, widget):
"""Configure the coloring of the widget"""
# Note: This will be dramatically simplified when colors
# are removed from the backend.

if self.pure:
# only IPythonWidget supports styling
return

# parse the colors arg down to current known labels
try:
colors = self.config.ZMQInteractiveShell.colors
Expand Down
6 changes: 3 additions & 3 deletions IPython/lib/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def get_connection_file(app=None):
If unspecified, the currently running app will be used
"""
if app is None:
from IPython.zmq.kernelapp import KernelApp
if not KernelApp.initialized():
from IPython.zmq.ipkernel import IPKernelApp
if not IPKernelApp.initialized():
raise RuntimeError("app not specified, and not in a running Kernel")

app = KernelApp.instance()
app = IPKernelApp.instance()
return filefind(app.connection_file, ['.', app.profile_dir.security_dir])

def find_connection_file(filename, profile=None):
Expand Down
Loading