简体   繁体   中英

how to handle close connection Exception in websockets and asyncio (Python)?

I am using websockets and asyncio in Python 3.6.3 on windows cygwin.

This is my code: 在此处输入图片说明

It was slightly simplified for reading.

It run and outputed correctly for a while, but later nothing was printed. I pressed ctrl+C, and got this on exiting:

Exception ignored in: <generator object WebSocketCommonProtocol.close_connection at 0x6fffe9349e8>

RuntimeError: generator ignored GeneratorExit

Did it means the try catch not working? or Did I do it the wrong way?

except:

You should never do such thing since it catches also service (non-error) exceptions such as GeneratorExit .

Change it with:

except Exception:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM