Format: application/x-python-code
1 o
2
3 -hu � @ 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
4 d� Zdd
5 � Z dd� Z
6 dd� Zdd� Zdd� Z
7 dS )�StatelessServerax
8 Base server class that handles basic concepts like application instance
9 creation/pooling, exception handling, and similar, for stateless protocols
10 (i.e. ones without actual incoming connections to the process)
11
12 Your code should override the handle() method, doing whatever it needs to,
13 and calling get_or_create_application_instance with a unique `scope_id`
14 and `scope` for the scope it wants to get.
15
16 If an application instance is found with the same `scope_id`, you are
17 given its input queue, otherwise one is made for you with the scope provided
18 and you are given that fresh new input queue. Either way, you should do
19 something like:
20
21 input_queue = self.get_or_create_application_instance(
22 "user-123456",
23 {"type": "testprotocol", "user_id": "123456", "username": "andrew"},
24 )
25 input_queue.put_nowait(message)
26
27 If you try and create an application instance and there are already
28 `max_application` instances, the oldest/least recently used one will be
29 reclaimed and shut down to make space.
30
31 Application coroutines that error will be found periodically (every 100ms
32 by default) and have their exceptions printed to the console. Override
33 application_exception() if you want to do more when this happens.
34
35 If you override run(), make sure you handle things like launching the
36 application checker.
37 g�������?�� c C s || _ || _i | _d S �N)�application�max_applications�application_instances)�selfr r � r �DC:\Users\shubh\Videos\agent\nova\Lib\site-packages\asgiref/server.py�__init__. s
38 zStatelessServer.__init__c C sJ t �� }t �| �� � z
39 |�| �� � W dS ty$ t�d� Y dS w )zD
40 Runs the asyncio event loop with our handler loop.
41 zExiting due to Ctrl-C/interruptN) �asyncio�get_event_loop�
42 ensure_future�application_checker�run_until_complete�handle�KeyboardInterrupt�logger�info)r
43 Z
44 event_loopr r r �run7 s �zStatelessServer.runc � �
45 �t d��)NzYou must implement handle()��NotImplementedError)r
46 r r r r B s �zStatelessServer.handlec � r )zM
47 Receives outbound sends from applications and handles them.
48 z%You must implement application_send()r )r
49 �scope�messager r r �application_sendE s �z StatelessServer.application_sendc s� |�j v rt�� �j | d<