To the meinheld professor who is indebted to me on a daily basis
There is a WebSocketMiddleware
that makes it easy to implement WebSockets for existing wsgi apps.
If it's a code written by a hetareyaro like me, it's very slow and unusable unless it's taken care of by meinheld, so I can't get up.
So, when I thought about making a recent cool-looking app that uses such WebSocket, Of course, mongodb will be chosen as a DB option with such momentum. yep.
So, mongodb while referring to Sample of applying meinheld WebSocketMiddleware to flask etc. written by the author of meinheld himself. I wonder if it will be like this when I try to build
main.py
from shimehari import Shimehari
from mongoengine import connect
from meinheld import server, middleware
import config
def connectDB():
connect(config['DB_NAME'])
app = Shimehari(__name__)
if __name__ == '__main__':
connectDB()
server.listen(("0.0.0.0", 3000))
server.run(middleware.WebSocketMiddleware(app))
$ (venv) bin/python main.py
People People People People People People
Sudden error <  ̄Y^Y^Y^Y^Y^Y^Y ̄
Traceback (most recent call last):
File "main.py", line 25, in <module>
connectDB()
File "/project/path/main.py", line 13, in connectDB
connect(config['DB_NAME'])
File "/project/path/lib/python2.7/site-packages/mongoengine/connection.py", line 162, in connect
return get_connection(alias)
File "/project/path/lib/python2.7/site-packages/mongoengine/connection.py", line 126, in get_connection
raise ConnectionError("Cannot connect to database %s :\n%s" % (alias, e))
mongoengine.connection.ConnectionError: Cannot connect to database default :
call from same greenlet
I don't know what you're talking about. I wondered if the host around the port was strange Suddenly I changed the implementation as follows and it worked.
main.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from shimehari import Shimehari
def connectDB():
connect(config['DB_NAME'])
app = Shimehari(__name__)
if __name__ == '__main__':
connectDB()
#import after connecting to db
from meinheld import server, middleware
server.listen(("0.0.0.0", 3000))
server.run(middleware.WebSocketMiddleware(app))
It's a natural thing for the mohawk people who are messing around with it! It may be something like that
I didn't come out at all when I googled
I think that there are more people who use node.js when doing WebSocket, so I think that's the case, while thinking
For the time being, it worked with this, so I'm glad
Is it better to replace connecetDB
with something like with
?
Recommended Posts