##// END OF EJS Templates
use shell namespaces in apply_request
MinRK -
Show More
@@ -495,7 +495,6 b' class Kernel(Configurable):'
495 495 content = parent[u'content']
496 496 bufs = parent[u'buffers']
497 497 msg_id = parent['header']['msg_id']
498 # bound = parent['header'].get('bound', False)
499 498 except:
500 499 self.log.error("Got bad msg: %s", parent, exc_info=True)
501 500 return
@@ -510,15 +509,11 b' class Kernel(Configurable):'
510 509 sys.displayhook.set_parent(parent)
511 510 sys.stdout.set_parent(parent)
512 511 sys.stderr.set_parent(parent)
513 # exec "f(*args,**kwargs)" in self.user_ns, self.user_ns
514 working = self.user_ns
515 # suffix =
512 working = self.shell.user_ns
513
516 514 prefix = "_"+str(msg_id).replace("-","")+"_"
517 515
518 516 f,args,kwargs = unpack_apply_message(bufs, working, copy=False)
519 # if bound:
520 # bound_ns = Namespace(working)
521 # args = [bound_ns]+list(args)
522 517
523 518 fname = getattr(f, '__name__', 'f')
524 519
@@ -532,13 +527,11 b' class Kernel(Configurable):'
532 527 working.update(ns)
533 528 code = "%s=%s(*%s,**%s)"%(resultname, fname, argname, kwargname)
534 529 try:
535 exec code in working,working
530 exec code in self.shell.user_global_ns, self.shell.user_ns
536 531 result = working.get(resultname)
537 532 finally:
538 533 for key in ns.iterkeys():
539 534 working.pop(key)
540 # if bound:
541 # working.update(bound_ns)
542 535
543 536 packed_result,buf = serialize_object(result)
544 537 result_buf = [packed_result]+buf
@@ -586,10 +579,9 b' class Kernel(Configurable):'
586 579
587 580 def clear_request(self, stream, idents, parent):
588 581 """Clear our namespace."""
589 self.user_ns = {}
582 self.shell.reset(False)
590 583 msg = self.session.send(stream, 'clear_reply', ident=idents, parent=parent,
591 584 content = dict(status='ok'))
592 self._initial_exec_lines()
593 585
594 586
595 587 #---------------------------------------------------------------------------
@@ -597,6 +589,14 b' class Kernel(Configurable):'
597 589 #---------------------------------------------------------------------------
598 590
599 591
592 def _wrap_exception(self, method=None):
593 # import here, because _wrap_exception is only used in parallel,
594 # and parallel has higher min pyzmq version
595 from IPython.parallel.error import wrap_exception
596 e_info = dict(engine_uuid=self.ident, engine_id=self.int_id, method=method)
597 content = wrap_exception(e_info)
598 return content
599
600 600 def _topic(self, topic):
601 601 """prefixed topic for IOPub messages"""
602 602 if self.int_id >= 0:
General Comments 0
You need to be logged in to leave comments. Login now