Show More
@@ -159,12 +159,24 b' class ParalleMagic(Plugin):' | |||
|
159 | 159 | self.autopx = False |
|
160 | 160 | print "%autopx disabled" |
|
161 | 161 | |
|
162 |
def pxrun_source(self, ipself, source, filename= |
|
|
163 | """A parallel replacement for InteractiveShell.run_source.""" | |
|
162 | def pxrun_source(self, ipself, source, filename=None, | |
|
163 | symbol='single', post_execute=True): | |
|
164 | ||
|
165 | # We need to ensure that the source is unicode from here on. | |
|
166 | if type(source)==str: | |
|
167 | usource = source.decode(ipself.stdin_encoding) | |
|
168 | else: | |
|
169 | usource = source | |
|
170 | ||
|
171 | if 0: # dbg | |
|
172 | print 'Source:', repr(source) # dbg | |
|
173 | print 'USource:', repr(usource) # dbg | |
|
174 | print 'type:', type(source) # dbg | |
|
175 | print 'encoding', ipself.stdin_encoding # dbg | |
|
164 | 176 | |
|
165 | 177 | try: |
|
166 |
code = ipself.compile(source |
|
|
167 | except (OverflowError, SyntaxError, ValueError): | |
|
178 | code = ipself.compile(usource, symbol, ipself.execution_count) | |
|
179 | except (OverflowError, SyntaxError, ValueError, TypeError, MemoryError): | |
|
168 | 180 | # Case 1 |
|
169 | 181 | ipself.showsyntaxerror(filename) |
|
170 | 182 | return None |
@@ -197,6 +209,6 b' def load_ipython_extension(ip):' | |||
|
197 | 209 | global _loaded |
|
198 | 210 | if not _loaded: |
|
199 | 211 | plugin = ParalleMagic(shell=ip, config=ip.config) |
|
200 |
ip.plugin_manager.register_plugin('parallel |
|
|
212 | ip.plugin_manager.register_plugin('parallelmagic', plugin) | |
|
201 | 213 | _loaded = True |
|
202 | 214 |
@@ -44,8 +44,8 b" warnings.filterwarnings('ignore', 'the sha module is deprecated'," | |||
|
44 | 44 | |
|
45 | 45 | import sys |
|
46 | 46 | |
|
47 | import twisted | |
|
47 | 48 | from twisted.internet import reactor |
|
48 | from twisted.internet.error import PotentialZombieWarning | |
|
49 | 49 | from twisted.python import log |
|
50 | 50 | |
|
51 | 51 | from IPython.kernel.clientconnector import ClientConnector, Cluster |
@@ -54,7 +54,6 b' from IPython.kernel.twistedutil import blockingCallFromThread' | |||
|
54 | 54 | |
|
55 | 55 | # These enable various things |
|
56 | 56 | from IPython.kernel import codeutil |
|
57 | # import IPython.kernel.magic | |
|
58 | 57 | |
|
59 | 58 | # Other things that the user will need |
|
60 | 59 | from IPython.kernel.task import MapTask, StringTask |
@@ -64,6 +63,10 b' from IPython.kernel.error import CompositeError' | |||
|
64 | 63 | # Code |
|
65 | 64 | #------------------------------------------------------------------------------- |
|
66 | 65 | |
|
66 | # PotentialZombieWarning is deprecated from Twisted 10.0.0 and above and | |
|
67 | # using the filter on > 10.0.0 creates a warning itself. | |
|
68 | if twisted.version.major < 10: | |
|
69 | from twisted.internet.error import PotentialZombieWarning | |
|
67 | 70 | warnings.simplefilter('ignore', PotentialZombieWarning) |
|
68 | 71 | |
|
69 | 72 | _client_tub = ClientConnector() |
@@ -77,6 +80,18 b' TaskClient = get_task_client' | |||
|
77 | 80 | # class below. But, it does work for now. |
|
78 | 81 | log.startLogging(sys.stdout, setStdout=0) |
|
79 | 82 | |
|
83 | def _result_list_printer(obj, p, cycle): | |
|
84 | if cycle: | |
|
85 | return p.text('ResultList(...)') | |
|
86 | return p.text(repr(obj)) | |
|
87 | ||
|
88 | # ResultList is a list subclass and will use the default pretty printer. | |
|
89 | # This overrides that to use the __repr__ of ResultList. | |
|
90 | ip = get_ipython() | |
|
91 | ip.displayhook.default_formatter.for_type_by_name( | |
|
92 | 'IPython.kernel.multiengineclient', 'ResultList', _result_list_printer | |
|
93 | ) | |
|
94 | ||
|
80 | 95 | # Now we start the reactor in a thread |
|
81 | 96 | rit = ReactorInThread() |
|
82 | 97 | rit.setDaemon(True) |
@@ -272,7 +272,7 b' class InteractiveMultiEngineClient(object):' | |||
|
272 | 272 | except NameError: |
|
273 | 273 | print "The IPython parallel magics (%result, %px, %autopx) only work within IPython." |
|
274 | 274 | else: |
|
275 |
pmagic = ip.plugin_manager.get_plugin('parallel |
|
|
275 | pmagic = ip.plugin_manager.get_plugin('parallelmagic') | |
|
276 | 276 | if pmagic is not None: |
|
277 | 277 | pmagic.active_multiengine_client = self |
|
278 | 278 | else: |
General Comments 0
You need to be logged in to leave comments.
Login now