本文整理汇总了Python中channels.generic.websocket.WebsocketConsumer方法的典型用法代码示例。如果您正苦于以下问题:Python websocket.WebsocketConsumer方法的具体用法?Python websocket.WebsocketConsumer怎么用?Python websocket.WebsocketConsumer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类channels.generic.websocket
的用法示例。
在下文中一共展示了websocket.WebsocketConsumer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: disconnect
# 需要导入模块: from channels.generic import websocket [as 别名]
# 或者: from channels.generic.websocket import WebsocketConsumer [as 别名]
def disconnect(self, close_code):
async_to_sync(self.channel_layer.group_discard)(self.scope['user'].username, self.channel_name)
# class StatsConsumer(WebsocketConsumer):
#
# def connect(self):
# async_to_sync(self.channel_layer.group_add)(self.scope['user'].username, self.channel_name)
#
# self.accept()
#
# def receive(self, text_data):
# key = '-'.join(('django-mstats-processlist', str(self.scope['user'].uid)))
# cache.set(key, 'start', timeout=None)
# show_processlist.delay(host=text_data, user=self.scope['user'].username, key=key)
#
# async_to_sync(self.channel_layer.group_send)(
# self.scope['user'].username,
# {
# "type": "user.message",
# "text": text_data,
# },
# )
#
# def user_message(self, event):
# self.send(text_data=event["text"])
#
# def disconnect(self, close_code):
# key = '-'.join(('django-mstats-processlist', str(self.scope['user'].uid)))
# cache.set(key, 'end', timeout=None)
# async_to_sync(self.channel_layer.group_discard)(self.scope['user'].username, self.channel_name)