我有两个操纵者:
@sio.event
async def connect(sid, environ):
print('connect', sid)
@sio.event
async def disconnect(sid, environ):
# perform some user management stuff
# perform some cleaning as well
print('disconnect', sid)我希望触发disconnect事件处理程序(就像我想在断开连接时执行一些特定操作一样),但是触发一个名为leaveWorkbench的定制事件。
sio.disconnect()协同器来调用偶数处理程序sio.disconnect()I以这样的方式发出事件disconnect:@sio.event
async def leaveWorkbench(sid):
await sio.emit('disconnect')(从文档上看似乎不是一个好主意,因为“保留”(?)+它会被客户端捕获,所以很可能不是一个有效的解决方案)
sio.discconectasync def disconnect_handler(sid):
# operations to be performed on disconnection
await sio.disconnect(sid)??
@sio.event
async def leaveWorkbench(sid):
await disconnect_handler(sid)
@sio.event
async def disconnect(sid):
await disconnect_handler(sid)最后,
上使用了session对象
发布于 2021-07-26 14:25:16
正确的方法是调用sio.disconnect(sid)。
但是请注意,disconnect()方法只是启动一个断开连接,然后在后台发生。最终将调用受影响客户端的断开处理程序,但它可能不是立即的(即可能需要一两秒钟)。还将通知客户端它正在断开连接。
https://stackoverflow.com/questions/68527566
复制相似问题