Question

I am trying to write a homework about map-reduce. I run in a terminal:

ioannis@ioannis-desktop:~$ python hw3.py

then in another terminal:

python mincemeat.py -p changeme localhost

Immediately in the former terminal, a bunch of stuff is typed:

ioannis@ioannis-desktop:~$ python hw3.py
error: uncaptured python exception, closing channel <mincemeat.ServerChannel connected 127.0.0.1:58061 at 0x7fabef5045a8> 
(<type 'exceptions.TypeError'>:'NoneType' object is not iterable
 [/usr/lib/python2.7/asyncore.py|read|83] 
 [/usr/lib/python2.7/asyncore.py|handle_read_event|449] 
 [/usr/lib/python2.7/asynchat.py|handle_read|158] 
 [/home/ioannis/mincemeat.py|found_terminator|82] 
 [/home/ioannis/mincemeat.py|process_command|280] 
 [/home/ioannis/mincemeat.py|process_command|123] 
 [/home/ioannis/mincemeat.py|respond_to_challenge|106] 
 [/home/ioannis/mincemeat.py|post_auth_init|289] 
 [/home/ioannis/mincemeat.py|start_new_task|258] 
 [/home/ioannis/mincemeat.py|next_task|304])
    ^CTraceback (most recent call last):
      File "hw3.py", line 54, in <module>
        results = s.run_server(password="changeme")
      File "/home/ioannis/mincemeat.py", line 220, in run_server
        self.close_all()
      File "/usr/lib/python2.7/asyncore.py", line 421, in __getattr__
        %(self.__class__.__name__, attr))
    AttributeError: Server instance has no attribute 'close_all'
    ioannis@ioannis-desktop:~$ python hw3.py

the code for hw3.py:

import mincemeat
import glob
from stopwords import allStopWords
text_files = glob.glob('/home/ioannis/Web Intelligence and Big Data/Week 3: Load - I/hw3data/hw3data/*')

def file_contents(file_name):
    f = open(file_name)
    try:
#        print f.read()     
        return f.read()
    except:
        print "exception!!!!!!"
    finally:
        f.close()

source = dict((file_name, file_contents(file_name))
    for file_name in text_files)

def mapfn(key, value):    
    for line in value.splitlines():
        print "I have reach that point!"
...........
...........

def reducefn(k, vs):
    result = sum(vs)
    return result

s = mincemeat.Server()
s.source = source
s.mapfn = mapfn
s.reducefn = reducefn

results = s.run_server(password="changeme")
print results

In the thread Python, Asyncore and forks, the following suggestion was made:

Change your handle_accept() to return immediately when accept() returns None.

In the file mincemeat.py there is a function:

def handle_accept(self):
    conn, addr = self.accept()
    sc = ServerChannel(conn, self)
    sc.password = self.password

Is the solution to my problem to change something in that function?

Was it helpful?

Solution

s.source = source needs to be s.datasource = source.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top