Forums

Do websockets work as in now? What are new alternatives?

Hello, I've been trying to create asynchronous view where users can see progress, success and failures in the template. I found out that there were two secure solutions for this, One with Ajax XHR and second with Websockets. Also i'm not quite sure if it is still possible with Ajax and i'm trying to avoid it because it requires specific form of Http response and context in Json format which can't quite serialize decimal values without certain encoder.

So i decided to choose more familiar, easy and useful way with the use of websockets. I would simply use parallel execution for my bot's script (from my tests, multiprocessing seems to work), And template would be loaded without waiting for the script. Then script/bot would send data containing status to the Javascript to let user know the process.

Now the main problem is that i'm not sure if websockets do work, I have seen an previous thread from 2013 and staff members replied that they were working on it, So my question is, Do websockets work as of now? If not is there any similar alternative to websockets that work in pythonanywhere for doing this action without using Ajax XHR?

Thanks in advance.

Hi there,

Unfortunately websockets do not currently work. You can try to use a third party websocket service like pusher in conjunction with PythonAnywhere though.

Conrad

@Conrad

Hello,

Thanks for the response, Is there any documentation regarding the usage of pusher in pythonanywhere?

Unfortunately we don't have any documentation on that. My guess for how to implement this would be:

  1. get your webapp to write to the processing request to a database table/file
  2. have a long running task that picks up the processing request and does the processing
  3. send an api call to pusher at various intervals (eg: once the task is picked up, once the task is done)