Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

message.data becoms None in spawned greenlets

Abierto
#194 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python

Línea de trabajo

Start at ws4py.websocket.WebSocket and the received_message entry point, then trace the message lifecycle when gevent.spawn runs the handler. Reproduce the reported behavior if possible and determine what should preserve message.data; done means spawned handlers receive the original data without requiring deepcopy, with a regression test if the project supports one.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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 the received_message method.

This works fine as long as it looks similar to the below:

def received_message(self, message):
    _self._on_received_message(message.data)

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))
Lenguaje dominante
Python
Estrellas
1.1k
Forks
286
Merge medio
1 d 19 h
PR fusionados (30 d)
2

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Lawouach/WebSocket-for-Python

Todos los issues de Lawouach/WebSocket-for-Python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.