mirror of
https://github.com/xfgryujk/blivedm.git
synced 2024-12-26 21:00:17 +08:00
8d7d63f1bb
close的设计参考了aiohttp 的ws client,非常感谢
26 lines
525 B
Python
26 lines
525 B
Python
# -*- coding: utf-8 -*-
|
|
|
|
import asyncio
|
|
from time import time
|
|
from blivedm import DanmuPrinter
|
|
|
|
async def test1():
|
|
connection = DanmuPrinter(23058, 0)
|
|
task_run = asyncio.ensure_future(connection.run_forever())
|
|
await asyncio.sleep(30)
|
|
print(time(), 'closing')
|
|
await connection.close()
|
|
print(time(), 'closed')
|
|
await task_run
|
|
print(time(), 'all done')
|
|
|
|
|
|
def main():
|
|
loop = asyncio.get_event_loop()
|
|
loop.run_until_complete(test1())
|
|
loop.close()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|