However, the moment I spawn the handler function into its own greenlet as below ..
from gevent import spawn
def received_message(self, message):
spawn(_self._on_received_message, message.data)
.. message.data becomes None somewhere between spawn and the moment _self._on_received_message gets called but at any rate _self._on_received_message receives None, the original data is lost by the time that method is called in its own greenlet.
The workaround is to deepcopy it before spawning the greenlet
from copy import deepcopy
from gevent import spawn
def received_message(self, message):
spawn(_self._on_received_message, deepcopy(message.data))
Hi there,
I don't have a self-contained test case but I can easily reproduce the following nevertheless in my project.
In a subclass of
ws4py.websocket.WebSocket
that is running in a gevent-based server I implemented thereceived_message
method.This works fine as long as it looks similar to the below:
However, the moment I spawn the handler function into its own greenlet as below ..
.. message.data becomes None somewhere between spawn and the moment _self._on_received_message gets called but at any rate _self._on_received_message receives None, the original data is lost by the time that method is called in its own greenlet.
The workaround is to deepcopy it before spawning the greenlet