我跑不了肉馅.py一堆未知的东西印到了终点站

2024-04-29 06:10:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在写一篇关于地图缩小的作业。我在一个终端上运行:

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

然后在另一个终端:

^{pr2}$

在前一个终端中,输入了一堆东西:

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

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

在线程Python, Asyncore and forks中,提出了以下建议:

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

在文件中肉馅.py有一个功能:

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

我的问题的解决方案是改变那个函数中的某些东西吗?在


Tags: nameinpyselfhomereadlibusr