Search code examples
pythonwebpyramid

Notifying user's browser of change without websockets


I'm developing intranet web app that is based on Pyramid with SQLAlchemy.

It eventually may (will) happen that 2 users will edit the same record. How can I handle the requirement to notify the user who started editing later that particular record is being edited by the first user?


Solution

  • Look into using Server Sent Events (SSE) instead of websockets. Pyramid itself can answer such requests without a thread constantly being consumed. SSE is supported by most browsers except IE, and there are probably shims for IE that allow it to work.

    Here's a Pyramid view that implements an SSE event stream:

    https://github.com/Pylons/substanced/blob/master/substanced/audit/views.py#L49