示例#1
0
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
        )
示例#2
0
文件: ipc.py 项目: Krukov/channels
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()
示例#3
0
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
示例#4
0
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()
示例#6
0
    def setUp(self):
        self.channel_layer = get_channel_layer()
        self.channel_layer.flush()

        self.message = MessageStub()
        self.engine = ChatEngine(self.message)
示例#7
0
# -*- 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()
示例#8
0
    def setUp(self):
        self.channel_layer = get_channel_layer()
        self.channel_layer.flush()

        self.message = MessageStub()
        self.engine = ChatEngine(self.message)
示例#9
0
# -*- 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()