OwlCyberSecurity - MANAGER
Edit File: server.cpython-39.pyc
a gH�fu � @ sH d dl Z d dlZd dlZd dlZddlmZ e�e�ZG dd� d�Z dS )� N� )�guarantee_single_callablec @ s^ e Zd ZdZdZddd�Zdd� Zdd � Zd d� Zdd � Z dd� Z dd� Zdd� Zdd� Z dS )�StatelessServerax Base server class that handles basic concepts like application instance creation/pooling, exception handling, and similar, for stateless protocols (i.e. ones without actual incoming connections to the process) Your code should override the handle() method, doing whatever it needs to, and calling get_or_create_application_instance with a unique `scope_id` and `scope` for the scope it wants to get. If an application instance is found with the same `scope_id`, you are given its input queue, otherwise one is made for you with the scope provided and you are given that fresh new input queue. Either way, you should do something like: input_queue = self.get_or_create_application_instance( "user-123456", {"type": "testprotocol", "user_id": "123456", "username": "andrew"}, ) input_queue.put_nowait(message) If you try and create an application instance and there are already `max_application` instances, the oldest/least recently used one will be reclaimed and shut down to make space. Application coroutines that error will be found periodically (every 100ms by default) and have their exceptions printed to the console. Override application_exception() if you want to do more when this happens. If you override run(), make sure you handle things like launching the application checker. g�������?�� c C s || _ || _i | _d S �N)�application�max_applications�application_instances)�selfr r � r �P/home/gouroczh/virtualenv/test/3.9/lib/python3.9/site-packages/asgiref/server.py�__init__. s zStatelessServer.__init__c C sJ t �� }t �| �� � z|�| �� � W n tyD t�d� Y n0 dS )zD Runs the asyncio event loop with our handler loop. zExiting due to Ctrl-C/interruptN) �asyncio�get_event_loop� ensure_future�application_checker�run_until_complete�handle�KeyboardInterrupt�logger�info)r Z event_loopr r r �run7 s zStatelessServer.runc � s t d��d S )NzYou must implement handle()��NotImplementedError)r r r r r B s zStatelessServer.handlec � s t d��dS )zM Receives outbound sends from applications and handles them. z%You must implement application_send()Nr )r �scope�messager r r �application_sendE s z StatelessServer.application_sendc s� |�j v r*t�� �j | d<