Python论坛  - 讨论区

标题:[python-chinese] 请教简单问题,使用try except的时机

2007年06月21日 星期四 10:06

Brightman mr.brightman在gmail.com
星期四 六月 21 10:06:36 HKT 2007

比如:
data = self.rfile.read(ssize)
self.wfile.write("y")
潜在下面的错误,由于socket连接断开,write就会有错误,是应该用try except
包起来,还是其他什么手段处理?(比如c中检察返回值),我不了解try
except,不敢随意使用try except,怕影响性能。请大家指教一下,谢谢!

Traceback (most recent call last):
File "/home/forum/Python-2.5/Lib/SocketServer.py", line 222, in
handle_request
self.process_request(request, client_address)
File "/home/forum/Python-2.5/Lib/SocketServer.py", line 241, in
process_request
self.finish_request(request, client_address)
File "/home/forum/Python-2.5/Lib/SocketServer.py", line 254, in
finish_request
self.RequestHandlerClass(request, client_address, self)
File "/home/forum/Python-2.5/Lib/SocketServer.py", line 521, in __init__
self.handle()
File "baoba.py", line 86, in handle
self.wfile.write("y")
File "/home/forum/Python-2.5/Lib/socket.py", line 261, in write
self.flush()
File "/home/forum/Python-2.5/Lib/socket.py", line 248, in flush
self._sock.sendall(buffer)
error: (32, 'Broken pipe')

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号