Is there any way to build an interactive terminal using Django Channels with it's current limitations?

480 Views Asked by At

It seems with Django Channels each time anything happens on the websocket there is no persistent state. Even within the same websocket connection, you can not preserve anything between each call to receive() on a class based consumer. If it can't be serialized into the channel_session, it can't be stored.

I assumed that the class based consumer would be persisted for the duration of the web socket connection.

What I'm trying to build is a simple terminal emulator, where a shell session would be created when the websocket connects. Read data would be passed as input to the shell and the shell's output would be passed out the websocket.

I can not find a way to persist anything between calls to receive(). It seems like they took all the bad things about HTTP and brought them over to websockets. With each call to conenct(), recieve(), and disconnect() the whole Consumer class is reinstantiated.

So am I missing something obvious. Can I make another thread and have it read from a Group?

Edit: The answers to this can be found in the comments below. You can hack around it. Channels 3.0 will not instantiate the Consumers on every receive call.

1

There are 1 best solutions below

0
On BEST ANSWER

The new version of Channels does not have this limitation. Consumers stay in memory for the duration of the websocket request.