##// END OF EJS Templates
Cleaned up embedded shell and added cleanup method to InteractiveShell....
Cleaned up embedded shell and added cleanup method to InteractiveShell. * Added explicit code in InteractiveShell to make sure it cleans itself up. This is now done by the single method .cleanup, that can be called to have InteractiveShell cleanup. We can't use __del__ because of the many cycles in our object graph. * The embedded shell is refactored to no embedding logic is in the base class. Thus, InteractiveShell no longer takes an ``embedded`` argument. Just use InteractiveShellEmbed. * Created a super simple top-level :func:`embed` function that creates an InteractiveShellEmbed and calls it.

File last commit:

r1338:72652d65
r2226:7053ea2c
Show More
pwordfreq.py
46 lines | 1.3 KiB | text/x-python | PythonLexer
#!/usr/bin/env python
"""Parallel word frequency counter."""
from itertools import repeat
from wordfreq import print_wordfreq, wordfreq
def pwordfreq(rc, text):
"""Parallel word frequency counter.
rc - An IPython RemoteController
text - The name of a string on the engines to do the freq count on.
"""
rc.execute('freqs = wordfreq(%s)' %text)
freqs_list = rc.pull('freqs')
word_set = set()
for f in freqs_list:
word_set.update(f.keys())
freqs = dict(zip(word_set, repeat(0)))
for f in freqs_list:
for word, count in f.iteritems():
freqs[word] += count
return freqs
if __name__ == '__main__':
# Create a MultiEngineClient
from IPython.kernel import client
ipc = client.MultiEngineClient()
# Run the wordfreq script on the engines.
ipc.run('wordfreq.py')
# Run the serial version
print "Serial word frequency count:"
text = open('davinci.txt').read()
freqs = wordfreq(text)
print_wordfreq(freqs, 10)
# The parallel version
print "\nParallel word frequency count:"
files = ['davinci%i.txt' % i for i in range(4)]
ipc.scatter('textfile', files)
ipc.execute('text = open(textfile[0]).read()')
pfreqs = pwordfreq(ipc,'text')
print_wordfreq(freqs)