Sanitary cycle of events and autobahns

I have a project written with Sanic

application = Sanic(__name__)
...
application.run(host=application.config.HOST, port=application.config.PORT,
                debug=application.config.DEBUG, log_config=application.config.LOG)

and my site has a section for real-time operations

for the real-time section, I want to use autobahn with a panic cycle

and I have a user chat protocol

class ChatServerProtocol(WebSocketServerProtocol):
    ....

and chat factory:

class ChatFactory(WebSocketServerFactory):
    ...

and I get the sanic event loop and set the factory to ChatFactory

async def after_server_start(app, loop):
    factory = ChatFactory(u"ws://127.0.0.1:9000")
    factory.protocol = ChatServerProtocol

    loop.set_task_factory(factory)

The above code does not work:

Error: Bad Request
Traceback (most recent call last):
  File "httptools/parser/parser.pyx", line 296, in httptools.parser.parser.cb_on_message_complete (httptools/parser/parser.c:4868)
File "/Users/XXX/Documents/Projects/sanic_env/lib/python3.6/site-packages/sanic/server.py", line 227, in on_message_complete
self.execute_request_handler()
File "/Users/XXX/Documents/Projects/sanic_env/lib/python3.6/site-packages/sanic/server.py", line 234, in execute_request_handler
self.stream_response))
File "uvloop/loop.pyx", line 1146, in uvloop.loop.Loop.create_task (uvloop/loop.c:24809)
TypeError: __call__() takes 1 positional argument but 3 were given

and Questions :

A: can I use the sanic event loop for autobahn?

B: If yes, how to do it?

+4
source share

Source: https://habr.com/ru/post/1690202/


All Articles