Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

message.data becoms None in spawned greenlets

Aperta
#194 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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))
Lingua principale
Python
Stelle
1.1k
Fork
286
Merge medio
1g 19h
PR unite (30g)
2

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Lawouach/WebSocket-for-Python

Tutte le issue di Lawouach/WebSocket-for-Python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.