PP常见错误分析

1.UnboundLocalError: local variable 'sresult' referenced before assignment * 错误描述:变量sresult未定义就使用 * 查看此处源码:
        try:
            worker.t.csend(sfunc)
            worker.t.send(sargs)
            sresult = worker.t.receive()
        except:
            if self._exiting:
                return
            if SHOW_EXPECTED_EXCEPTIONS:
                self.logger.debug("Exception in _run_local (possibly expected)", exc_info=True)

        job.finalize(sresult)
调试会发现,代码中存在和pp模块冲突的时候,如可执行体异常、运行子进程、可执行体中中文乱码等,运行到worker.t.csend(sfunc)或worker.t.send(sargs)时就会跳出,不会receive数据,故执行job.finalize(sresult)就会出上述错误 * 解决方案: 1.检查上述提供的几种错误可能,可能还有未提到的,可执行体异常和可执行体中乱码可以通过调试发现、解决,运行子进程暂时未有很好的解决办法,一种是用print os.popen(cmdString).read()代替os.system(cmdString)等执行子进程的的方法,主要是避免进程输出定向冲突问题。 2.另一种是我试过的,可以解决此类错误,但还没完全弄清楚,使用subprocess时指定输出,如下:
sp = subprocess.Popen(cmd, stdout=subprocess.PIPE,\
                        stdin=subprocess.PIPE,stderr=subprocess.PIPE)
if sp.wait() == 0:
    pass
else:
    pass
此问题应该是在pp下一版中解决:http://www.parallelpython.com/component/option,com_smf/Itemid,29/topic,604.0
2.timeout: timed out * 错误描述:Server端timeout,被客户端强制中断请求的连接
Traceback (most recent call last):
  File "/usr/bin/ppserver.py", line 173, in crun
    mysocket.receive()
  File "/usr/lib/python2.6/site-packages/pptransport.py", line 176, in receive
    msg = self.socket.recv(e_size-r_size)
timeout: timed out
* 主要原因: 客户端(控制端)向server传输的内容过长,或socket连接的时间设置过短 总而言之就是:Client向Server发起请求,然后传输数据,数据尚未传输完毕,就到了Client端设置的传输Timeout时间,Client端就会主动断开此次请求连接,故Server端就会报此错误 * 解决方案: 1.因pp模块的Server没有提供设置timeout的接口,可修改pp模块中的TRANSPORT_SOCKET_TIMEOUT,将此值设置大一些,默认为5s 此问题应该是在pp论坛的描述:http://www.parallelpython.com/component/option,com_smf/Itemid,29/topic,521.0 pp常见问题及解答:http://www.parallelpython.com/component/option,com_smf/Itemid,29/topic,210.msg1344#msg1344
posted @ 2011-09-02 13:03  残夜  阅读(334)  评论(0编辑  收藏  举报