更新时间:2023-12-01 20:44:40
您可以在打开的连接上附加超时回调函数.这是您的示例的额外代码.
You can attach a timeout call-back function on the opened connection. Here is the extra code for your example.
timeout = 60
def on_timeout():
global connection
connection.close()
connection.add_timeout(timeout, on_timeout)