How to use the asgiref.base_layer.BaseChannelLayer function in asgiref

To help you get started, we’ve selected a few asgiref examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github django / asgiref / asgiref / View on Github external
from __future__ import unicode_literals

from copy import deepcopy
import random
import six
import string
import time
import threading
from collections import deque

from .base_layer import BaseChannelLayer

class ChannelLayer(BaseChannelLayer):
    In memory channel layer object; a single one is instantiated as
    "channel_layer" for easy shared use. Only allows global capacity config.

    def __init__(self, expiry=60, group_expiry=86400, capacity=10, channel_capacity=None):
        super(ChannelLayer, self).__init__(
        self.thread_lock = threading.Lock()
        # Storage for state
        self._channels = {}
        self._groups = {}
github django / asgi_ipc / View on Github external
import random
import six
import string
import struct
import threading
import time
from asgiref.base_layer import BaseChannelLayer

import pkg_resources
import posix_ipc

__version__ = pkg_resources.require('asgi_ipc')[0].version
MB = 1024 * 1024

class IPCChannelLayer(BaseChannelLayer):
    Posix IPC backed channel layer, using the posix_ipc module's shared memory
    and sempahore components.

    It uses mmap'd shared memory areas to store msgpack'd versions of the
    datastructures, with a semaphore as a read/write lock to control access
    to the data area (all operations currently lock the entire memory segment).

    POSIX IPC Message Queues are not used as their default limits under most
    kernels are too small (8KB messages and 256 queues max); channels is a
    little... heavier than that.

    def __init__(self, prefix="asgi", expiry=60, group_expiry=86400,
                 capacity=10, channel_capacity=None,
                 channel_memory=100 * MB, group_memory=20 * MB):