def send_or_wait(send_func: Any, *args: Any, **kwargs: Any) -> None: """ Wrapper for channels' send() method. If the method send() raises ChannelFull exception the worker waits for 20 milliseconds and tries again. After 5 secondes it gives up, drops the channel message and writes a warning to stderr. Django channels' consumer atomicity feature is disabled. """ kwargs['immediately'] = True for i in range(250): try: send_func(*args, **kwargs) except get_channel_layer().ChannelFull: time.sleep(0.02) else: break else: warnings.warn( 'Channel layer is full. Channel message dropped.', RuntimeWarning )
import os from channels.asgi import get_channel_layer import asgi_ipc os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings.channels_ipc") channel_layer = get_channel_layer()
def get_session_from_group(group_name, session=None): channel_list = get_channel_layer().group_channels(group_name).keys() sessions = session_for_reply_channel(channel_list[0]) if session is not None: sessions = sessions.get(session, None) return sessions
import os import channels os.environ.setdefault("DJANGO_SETTINGS_MODULE", "base_project.settings") from channels.asgi import get_channel_layer channel_layer = get_channel_layer()
import os from channels.asgi import get_channel_layer os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{cookiecutter.project_name}}.settings') application = get_channel_layer()
def setUp(self): self.channel_layer = get_channel_layer() self.channel_layer.flush() self.message = MessageStub() self.engine = ChatEngine(self.message)
# -*- coding:utf-8 -*- # !/usr/bin/env python # Time 18-1-11 # Author Yo # Email [email protected] from __future__ import absolute_import, unicode_literals import os from channels import asgi os.environ.setdefault("DJANGO_SETTINGS_MODULE", "deveops.settings") #这里填的是你的配置文件settings.py的位置 channel_layer = asgi.get_channel_layer()
# -*- coding:utf-8 -*- # !/usr/bin/env python # Time 18-1-11 # Author Yo # Email [email protected] from __future__ import absolute_import,unicode_literals import os from channels import asgi os.environ.setdefault("DJANGO_SETTINGS_MODULE", "deveops.settings") #这里填的是你的配置文件settings.py的位置 channel_layer = asgi.get_channel_layer()