Show More
@@ -159,12 +159,24 b' class ParalleMagic(Plugin):' | |||||
159 | self.autopx = False |
|
159 | self.autopx = False | |
160 | print "%autopx disabled" |
|
160 | print "%autopx disabled" | |
161 |
|
161 | |||
162 |
def pxrun_source(self, ipself, source, filename= |
|
162 | def pxrun_source(self, ipself, source, filename=None, | |
163 | """A parallel replacement for InteractiveShell.run_source.""" |
|
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 | try: |
|
177 | try: | |
166 |
code = ipself.compile(source |
|
178 | code = ipself.compile(usource, symbol, ipself.execution_count) | |
167 | except (OverflowError, SyntaxError, ValueError): |
|
179 | except (OverflowError, SyntaxError, ValueError, TypeError, MemoryError): | |
168 | # Case 1 |
|
180 | # Case 1 | |
169 | ipself.showsyntaxerror(filename) |
|
181 | ipself.showsyntaxerror(filename) | |
170 | return None |
|
182 | return None | |
@@ -197,6 +209,6 b' def load_ipython_extension(ip):' | |||||
197 | global _loaded |
|
209 | global _loaded | |
198 | if not _loaded: |
|
210 | if not _loaded: | |
199 | plugin = ParalleMagic(shell=ip, config=ip.config) |
|
211 | plugin = ParalleMagic(shell=ip, config=ip.config) | |
200 |
ip.plugin_manager.register_plugin('parallel |
|
212 | ip.plugin_manager.register_plugin('parallelmagic', plugin) | |
201 | _loaded = True |
|
213 | _loaded = True | |
202 |
|
214 |
@@ -44,8 +44,8 b" warnings.filterwarnings('ignore', 'the sha module is deprecated'," | |||||
44 |
|
44 | |||
45 | import sys |
|
45 | import sys | |
46 |
|
46 | |||
|
47 | import twisted | |||
47 | from twisted.internet import reactor |
|
48 | from twisted.internet import reactor | |
48 | from twisted.internet.error import PotentialZombieWarning |
|
|||
49 | from twisted.python import log |
|
49 | from twisted.python import log | |
50 |
|
50 | |||
51 | from IPython.kernel.clientconnector import ClientConnector, Cluster |
|
51 | from IPython.kernel.clientconnector import ClientConnector, Cluster | |
@@ -54,7 +54,6 b' from IPython.kernel.twistedutil import blockingCallFromThread' | |||||
54 |
|
54 | |||
55 | # These enable various things |
|
55 | # These enable various things | |
56 | from IPython.kernel import codeutil |
|
56 | from IPython.kernel import codeutil | |
57 | # import IPython.kernel.magic |
|
|||
58 |
|
57 | |||
59 | # Other things that the user will need |
|
58 | # Other things that the user will need | |
60 | from IPython.kernel.task import MapTask, StringTask |
|
59 | from IPython.kernel.task import MapTask, StringTask | |
@@ -64,6 +63,10 b' from IPython.kernel.error import CompositeError' | |||||
64 | # Code |
|
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 | warnings.simplefilter('ignore', PotentialZombieWarning) |
|
70 | warnings.simplefilter('ignore', PotentialZombieWarning) | |
68 |
|
71 | |||
69 | _client_tub = ClientConnector() |
|
72 | _client_tub = ClientConnector() | |
@@ -77,6 +80,18 b' TaskClient = get_task_client' | |||||
77 | # class below. But, it does work for now. |
|
80 | # class below. But, it does work for now. | |
78 | log.startLogging(sys.stdout, setStdout=0) |
|
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 | # Now we start the reactor in a thread |
|
95 | # Now we start the reactor in a thread | |
81 | rit = ReactorInThread() |
|
96 | rit = ReactorInThread() | |
82 | rit.setDaemon(True) |
|
97 | rit.setDaemon(True) |
@@ -272,7 +272,7 b' class InteractiveMultiEngineClient(object):' | |||||
272 | except NameError: |
|
272 | except NameError: | |
273 | print "The IPython parallel magics (%result, %px, %autopx) only work within IPython." |
|
273 | print "The IPython parallel magics (%result, %px, %autopx) only work within IPython." | |
274 | else: |
|
274 | else: | |
275 |
pmagic = ip.plugin_manager.get_plugin('parallel |
|
275 | pmagic = ip.plugin_manager.get_plugin('parallelmagic') | |
276 | if pmagic is not None: |
|
276 | if pmagic is not None: | |
277 | pmagic.active_multiengine_client = self |
|
277 | pmagic.active_multiengine_client = self | |
278 | else: |
|
278 | else: |
General Comments 0
You need to be logged in to leave comments.
Login now