gpt4 book ai didi

python - 在线程中捕获中断的系统调用

转载 作者:行者123 更新时间:2023-11-28 16:46:26 24 4
gpt4 key购买 nike

我有一个使用 envisage 框架的客户端-服务器应用程序,我正在使用线程来处理连接,这是代码中的一个标记

    ....
SocketServer.TCPServer.allow_reuse_address = True
self.server = TCPFactory( ( HOST, PORT ), TCPRequestHandler, self.application)

self.server_thread = threading.Thread( target = self.server.serve_forever )

self.server_thread.setDaemon( True )
self.server_thread.start()

class TCPFactory( SocketServer.ThreadingTCPServer ):
def __init__( self, server_address, RequestHandlerClass, application ):
SocketServer.ThreadingTCPServer.__init__( self, server_address, RequestHandlerClass )
self.application = application

class TCPRequestHandler( SocketServer.BaseRequestHandler ):
""""""
def setup( self ):
.....

在 envisage 框架中,我调用了 open_file( ) 函数,它给了我们一个弹出窗口,但是当这个窗口出现时,我收到了以下错误

Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 504, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/lib/python2.7/SocketServer.py", line 225, in serve_forever
r, w, e = select.select([self], [], [], poll_interval)
error: (4, 'Interrupted system call')

我该如何处理这个错误?

最佳答案

在 Armin Rigo 发表评论后,我修改了 SockeServer.py

def serve_forever(self, poll_interval=0.5):
"""Handle one request at a time until shutdown.

Polls for shutdown every poll_interval seconds. Ignores
self.timeout. If you need to do periodic tasks, do them in
another thread.
"""
self.__is_shut_down.clear()
try:
while not self.__shutdown_request:
# XXX: Consider using another file descriptor or
# connecting to the socket to wake this up instead of
# polling. Polling reduces our responsiveness to a
# shutdown request and wastes cpu at all other times.
try:
r, w, e = select.select([self], [], [], poll_interval)
except select.error as ex:
#print ex
if ex[0] == 4:
continue
else:
raise
if self in r:
self._handle_request_noblock()
finally:
self.__shutdown_request = False
self.__is_shut_down.set()

关于python - 在线程中捕获中断的系统调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13414029/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com