home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- __docformat__ = 'restructuredtext en'
- import new
- from IPython.iplib import InteractiveShell
- from IPython.Shell import MTInteractiveShell
- from twisted.internet.defer import Deferred
- NO_ACTIVE_CONTROLLER = '\nError: No Controller is activated\nUse activate() on a RemoteController object to activate it for magics.\n'
-
- def magic_result(self, parameter_s = ''):
-
- try:
- activeController = __IPYTHON__.activeController
- except AttributeError:
- print NO_ACTIVE_CONTROLLER
-
-
- try:
- index = int(parameter_s)
- except:
- index = None
-
- result = activeController.get_result(index)
- return result
-
-
- def magic_px(self, parameter_s = ''):
-
- try:
- activeController = __IPYTHON__.activeController
- except AttributeError:
- print NO_ACTIVE_CONTROLLER
-
- print 'Parallel execution on engines: %s' % activeController.targets
- result = activeController.execute(parameter_s)
- return result
-
-
- def pxrunsource(self, source, filename = '<input>', symbol = 'single'):
-
- try:
- code = self.compile(source, filename, symbol)
- except (OverflowError, SyntaxError, ValueError):
- self.showsyntaxerror(filename)
- return None
-
- if code is None:
- return True
- if '_ip.magic("%autopx' in source or '_ip.magic("autopx' in source:
- _disable_autopx(self)
- return False
-
- try:
- result = self.activeController.execute(source)
- except:
- '_ip.magic("autopx' in source
- code is None
- self.showtraceback()
-
- print result.__repr__()
- return False
-
-
- def magic_autopx(self, parameter_s = ''):
- if hasattr(self, 'autopx'):
- if self.autopx == True:
- _disable_autopx(self)
- else:
- _enable_autopx(self)
- else:
- _enable_autopx(self)
-
-
- def _enable_autopx(self):
-
- try:
- activeController = __IPYTHON__.activeController
- except AttributeError:
- print 'No active RemoteController found, use RemoteController.activate().'
-
- self._original_runsource = self.runsource
- self.runsource = new.instancemethod(pxrunsource, self, self.__class__)
- self.autopx = True
- print 'Auto Parallel Enabled\nType %autopx to disable'
-
-
- def _disable_autopx(self):
- if hasattr(self, 'autopx'):
- if self.autopx == True:
- self.runsource = self._original_runsource
- self.autopx = False
- print 'Auto Parallel Disabled'
-
-
-
- InteractiveShell.magic_result = magic_result
- InteractiveShell.magic_px = magic_px
- InteractiveShell.magic_autopx = magic_autopx
- del magic_result
- del magic_px
- del magic_autopx
-