Search code examples
socket.iopyramidgunicorn

Q: How to integrate Pyramid 1.5 and Socket.IO 1.3?


I'm facing a problem while using Pyramid Framework 1.5 and Gevent-socketio in the server-side and Socket.IO V1.3 in the client side. The problem I have is that when I am opening a socket in the client side the server throws Internal Server Error (500). Also, the terminal outputs the following lines:

    socket = environ['socketio']
KeyError: 'socketio'

I've search about this problem and I read that it has something to do with the WSGI server I'm using (Which is currently Gunicorn. Maybe the way I am using it or set it up is wrong) but I couldn't find any good resource regard that issue.

I have few questions:

  1. First, Is there any good integration between Pyramid and the new Socket.IO V1.3 (The gevent-socketio project haven't updated in the last 1 year and since then Socket.IO V1 published with major changes).
  2. I read that I have to set up Gunicorn with Gevent or something but I couldn't do so. Any good resource or explanation about that?
  3. Last but not least, off topic, when in production, how do people run their app? Using the terminal in the server? It sounds somewhat weird. Could someone explain how I should run the app in the right way using Gunicorn and Pyramid when in production (and not)? What file should I run and how? What it should contain?

Thanks!

UPDATE:
Maybe I wasn't clear enough but when I am using older releases (For example, Socket.IO V0.9.6) the problem doesn't occur. but when I am changing the JavaScript file from Socket.io version 0.9.6 to Socket.IO version 1 (and above) the problem shows up.


Solution

  • 1) The integration of Pyramid and Socket.IO has already been done for you: https://github.com/abourget/gevent-socketio

    2) You can see the Gunicorn documtention for information on setting it up, including what to put in Pyramid's development.ini/production.ini files (Paster): http://docs.gunicorn.org/en/develop/configure.html#paster-applications Additional reading: https://www.digitalocean.com/community/tutorials/how-to-deploy-python-wsgi-apps-using-gunicorn-http-server-behind-nginx#serving-python-web-applications-with-gunicorn

    3) Here is information about deploying your web app for production (Nginx is a very popular alternative to Apache): http://pyramid-cookbook.readthedocs.org/en/latest/deployment/nginx.html