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 realtime operations
for realtime section i want to use autobahn with sanic loop
and i have custom chat protocol
class ChatServerProtocol(WebSocketServerProtocol):
....
and chat factory:
class ChatFactory(WebSocketServerFactory):
...
and i get sanic event loop and set 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 fails:
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 sanic event loop for autobahn?
B: If yes, how should it be done?