diff --git a/IPython/config/loader.py b/IPython/config/loader.py index 4956c18..cfbd92b 100644 --- a/IPython/config/loader.py +++ b/IPython/config/loader.py @@ -363,7 +363,7 @@ class CommandLineConfigLoader(ConfigLoader): for sec,c in cfg.iteritems(): self.config[sec].update(c) else: - raise ValueError("Invalid flag: '%s'"%raw) + raise TypeError("Invalid flag: %r" % cfg) # raw --identifier=value pattern # but *also* accept '-' as wordsep, for aliases diff --git a/IPython/core/magic.py b/IPython/core/magic.py index 4996c20..c86c2be 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -937,11 +937,6 @@ Currently the magic system has the following functions:\n""" vsize = var.size vbytes = vsize*var.itemsize vdtype = var.dtype - else: - # Numeric - vsize = Numeric.size(var) - vbytes = vsize*var.itemsize() - vdtype = var.typecode() if vbytes < 100000: print aformat % (vshape,vsize,vdtype,vbytes) @@ -2321,7 +2316,7 @@ Currently the magic system has the following functions:\n""" try: last_call[0] = self.shell.displayhook.prompt_count if not opts_prev: - last_call[1] = parameter_s + last_call[1] = args except: pass diff --git a/IPython/frontend/html/notebook/clustermanager.py b/IPython/frontend/html/notebook/clustermanager.py index 6a28fa4..efc0e7a 100644 --- a/IPython/frontend/html/notebook/clustermanager.py +++ b/IPython/frontend/html/notebook/clustermanager.py @@ -172,4 +172,4 @@ class ClusterManager(LoggingConfigurable): def stop_all_clusters(self): for p in self.profiles.keys(): - self.stop_cluster(profile) + self.stop_cluster(p) diff --git a/IPython/frontend/terminal/interactiveshell.py b/IPython/frontend/terminal/interactiveshell.py index 37ad352..1c3e13a 100644 --- a/IPython/frontend/terminal/interactiveshell.py +++ b/IPython/frontend/terminal/interactiveshell.py @@ -26,7 +26,7 @@ try: except: from IPython.utils.nested_context import nested -from IPython.core.error import TryNext +from IPython.core.error import TryNext, UsageError from IPython.core.usage import interactive_usage, default_banner from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC from IPython.core.pylabtools import pylab_activate diff --git a/IPython/parallel/controller/scheduler.py b/IPython/parallel/controller/scheduler.py index 400e16c..3f947b1 100644 --- a/IPython/parallel/controller/scheduler.py +++ b/IPython/parallel/controller/scheduler.py @@ -512,7 +512,7 @@ class TaskScheduler(SessionFactory): return False if job.targets: # check blacklist+targets for impossibility - job.targets.difference_update(blacklist) + job.targets.difference_update(job.blacklist) if not job.targets or not job.targets.intersection(self.targets): self.depending[msg_id] = job self.fail_unreachable(msg_id) diff --git a/IPython/parallel/engine/kernelstarter.py b/IPython/parallel/engine/kernelstarter.py deleted file mode 100644 index 4f53d39..0000000 --- a/IPython/parallel/engine/kernelstarter.py +++ /dev/null @@ -1,230 +0,0 @@ -"""KernelStarter class that intercepts Control Queue messages, and handles process management. - -Authors: - -* Min RK -""" -#----------------------------------------------------------------------------- -# Copyright (C) 2010-2011 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -from zmq.eventloop import ioloop - -from IPython.zmq.session import Session - -class KernelStarter(object): - """Object for resetting/killing the Kernel.""" - - - def __init__(self, session, upstream, downstream, *kernel_args, **kernel_kwargs): - self.session = session - self.upstream = upstream - self.downstream = downstream - self.kernel_args = kernel_args - self.kernel_kwargs = kernel_kwargs - self.handlers = {} - for method in 'shutdown_request shutdown_reply'.split(): - self.handlers[method] = getattr(self, method) - - def start(self): - self.upstream.on_recv(self.dispatch_request) - self.downstream.on_recv(self.dispatch_reply) - - #-------------------------------------------------------------------------- - # Dispatch methods - #-------------------------------------------------------------------------- - - def dispatch_request(self, raw_msg): - idents, msg = self.session.feed_identities() - try: - msg = self.session.unserialize(msg, content=False) - except: - print ("bad msg: %s"%msg) - - msgtype = msg['header']['msg_type'] - handler = self.handlers.get(msgtype, None) - if handler is None: - self.downstream.send_multipart(raw_msg, copy=False) - else: - handler(msg) - - def dispatch_reply(self, raw_msg): - idents, msg = self.session.feed_identities() - try: - msg = self.session.unserialize(msg, content=False) - except: - print ("bad msg: %s"%msg) - - msgtype = msg['header']['msg_type'] - handler = self.handlers.get(msgtype, None) - if handler is None: - self.upstream.send_multipart(raw_msg, copy=False) - else: - handler(msg) - - #-------------------------------------------------------------------------- - # Handlers - #-------------------------------------------------------------------------- - - def shutdown_request(self, msg): - """""" - self.downstream.send_multipart(msg) - - #-------------------------------------------------------------------------- - # Kernel process management methods, from KernelManager: - #-------------------------------------------------------------------------- - - def _check_local(addr): - if isinstance(addr, tuple): - addr = addr[0] - return addr in LOCAL_IPS - - def start_kernel(self, **kw): - """Starts a kernel process and configures the manager to use it. - - If random ports (port=0) are being used, this method must be called - before the channels are created. - - Parameters: - ----------- - ipython : bool, optional (default True) - Whether to use an IPython kernel instead of a plain Python kernel. - """ - self.kernel = Process(target=make_kernel, args=self.kernel_args, - kwargs=self.kernel_kwargs) - - def shutdown_kernel(self, restart=False): - """ Attempts to the stop the kernel process cleanly. If the kernel - cannot be stopped, it is killed, if possible. - """ - # FIXME: Shutdown does not work on Windows due to ZMQ errors! - if sys.platform == 'win32': - self.kill_kernel() - return - - # Don't send any additional kernel kill messages immediately, to give - # the kernel a chance to properly execute shutdown actions. Wait for at - # most 1s, checking every 0.1s. - self.xreq_channel.shutdown(restart=restart) - for i in range(10): - if self.is_alive: - time.sleep(0.1) - else: - break - else: - # OK, we've waited long enough. - if self.has_kernel: - self.kill_kernel() - - def restart_kernel(self, now=False): - """Restarts a kernel with the same arguments that were used to launch - it. If the old kernel was launched with random ports, the same ports - will be used for the new kernel. - - Parameters - ---------- - now : bool, optional - If True, the kernel is forcefully restarted *immediately*, without - having a chance to do any cleanup action. Otherwise the kernel is - given 1s to clean up before a forceful restart is issued. - - In all cases the kernel is restarted, the only difference is whether - it is given a chance to perform a clean shutdown or not. - """ - if self._launch_args is None: - raise RuntimeError("Cannot restart the kernel. " - "No previous call to 'start_kernel'.") - else: - if self.has_kernel: - if now: - self.kill_kernel() - else: - self.shutdown_kernel(restart=True) - self.start_kernel(**self._launch_args) - - # FIXME: Messages get dropped in Windows due to probable ZMQ bug - # unless there is some delay here. - if sys.platform == 'win32': - time.sleep(0.2) - - @property - def has_kernel(self): - """Returns whether a kernel process has been specified for the kernel - manager. - """ - return self.kernel is not None - - def kill_kernel(self): - """ Kill the running kernel. """ - if self.has_kernel: - # Pause the heart beat channel if it exists. - if self._hb_channel is not None: - self._hb_channel.pause() - - # Attempt to kill the kernel. - try: - self.kernel.kill() - except OSError, e: - # In Windows, we will get an Access Denied error if the process - # has already terminated. Ignore it. - if not (sys.platform == 'win32' and e.winerror == 5): - raise - self.kernel = None - else: - raise RuntimeError("Cannot kill kernel. No kernel is running!") - - def interrupt_kernel(self): - """ Interrupts the kernel. Unlike ``signal_kernel``, this operation is - well supported on all platforms. - """ - if self.has_kernel: - if sys.platform == 'win32': - from parentpoller import ParentPollerWindows as Poller - Poller.send_interrupt(self.kernel.win32_interrupt_event) - else: - self.kernel.send_signal(signal.SIGINT) - else: - raise RuntimeError("Cannot interrupt kernel. No kernel is running!") - - def signal_kernel(self, signum): - """ Sends a signal to the kernel. Note that since only SIGTERM is - supported on Windows, this function is only useful on Unix systems. - """ - if self.has_kernel: - self.kernel.send_signal(signum) - else: - raise RuntimeError("Cannot signal kernel. No kernel is running!") - - @property - def is_alive(self): - """Is the kernel process still running?""" - # FIXME: not using a heartbeat means this method is broken for any - # remote kernel, it's only capable of handling local kernels. - if self.has_kernel: - if self.kernel.poll() is None: - return True - else: - return False - else: - # We didn't start the kernel with this KernelManager so we don't - # know if it is running. We should use a heartbeat for this case. - return True - - -def make_starter(up_addr, down_addr, *args, **kwargs): - """entry point function for launching a kernelstarter in a subprocess""" - loop = ioloop.IOLoop.instance() - ctx = zmq.Context() - session = Session() - upstream = zmqstream.ZMQStream(ctx.socket(zmq.DEALER),loop) - upstream.connect(up_addr) - downstream = zmqstream.ZMQStream(ctx.socket(zmq.DEALER),loop) - downstream.connect(down_addr) - - starter = KernelStarter(session, upstream, downstream, *args, **kwargs) - starter.start() - loop.start() - diff --git a/IPython/parallel/tests/__init__.py b/IPython/parallel/tests/__init__.py index cb7d960..70d88c6 100644 --- a/IPython/parallel/tests/__init__.py +++ b/IPython/parallel/tests/__init__.py @@ -21,7 +21,9 @@ from IPython.parallel import Client from IPython.parallel.apps.launcher import (LocalProcessLauncher, ipengine_cmd_argv, ipcontroller_cmd_argv, - SIGKILL) + SIGKILL, + ProcessStateError, +) # globals launchers = [] diff --git a/IPython/utils/pickleshare.py b/IPython/utils/pickleshare.py index be5cd04..08cf8ea 100755 --- a/IPython/utils/pickleshare.py +++ b/IPython/utils/pickleshare.py @@ -191,10 +191,10 @@ class PickleShareDB(collections.MutableMapping): return [self._normalized(p) for p in files if p.isfile()] def __iter__(self): - return iter(keys) + return iter(self.keys()) def __len__(self): - return len(keys) + return len(self.keys()) def uncache(self,*items): """ Removes all, or specified items from cache diff --git a/IPython/utils/tests/test_traitlets.py b/IPython/utils/tests/test_traitlets.py index 7ed9f68..f893372 100644 --- a/IPython/utils/tests/test_traitlets.py +++ b/IPython/utils/tests/test_traitlets.py @@ -24,6 +24,8 @@ Authors: import sys from unittest import TestCase +from nose import SkipTest + from IPython.utils.traitlets import ( HasTraits, MetaHasTraits, TraitType, Any, CBytes, Int, Long, Integer, Float, Complex, Bytes, Unicode, TraitError, diff --git a/IPython/zmq/completer.py b/IPython/zmq/completer.py index a5f3192..65ba51d 100644 --- a/IPython/zmq/completer.py +++ b/IPython/zmq/completer.py @@ -59,7 +59,7 @@ class ClientCompleter(object): # Give the kernel up to 0.5s to respond for i in range(5): ident,rep = self.session.recv(self.socket) - rep = Message(rep) + rep = session.Message(rep) if rep is not None and rep.msg_type == 'complete_reply': matches = rep.content.matches break diff --git a/IPython/zmq/frontend.py b/IPython/zmq/frontend.py index 8b97639..79899dc 100755 --- a/IPython/zmq/frontend.py +++ b/IPython/zmq/frontend.py @@ -18,6 +18,7 @@ import zmq import session import completer from IPython.utils.localinterfaces import LOCALHOST +from IPython.zmq.session import Message #----------------------------------------------------------------------------- # Classes and functions