[Stackless] how does my tasklets and objects get freed

Péter Szabó ptspts+stackless at gmail.com
Thu Jan 28 12:25:33 CET 2010


Hi,

I'm using Stackless 2.6 with some Pyrex (C) code, and I'd like to make
sure that my objects won't be free()d too early (by reference counting
or garbage collection).

I have a C function like this:

void MyFunction() {
 struct event_t ev;
 PyTaskletObject *tasklet;
 ...
 tasklet = PyStackless_GetCurrent();
 event_set(&ev, ..., ..., ..., (void*)tasklet);
 event_add(&ev, NULL)
 PyStackless_Schedule(None, 1);  /* stackless.schdule_remove() */
 ...
 Py_DECREF(tasklet);
}

I'm afraid that after the call to PyStackless_Schedule, it may happen
that there will be no reference to this tasklet, so the garbage
collector might free() it at some point. I want to prevent this from
happening, the tasklet must be kept until it gets scheduled again, and
Py_DECREF(tasklet) is run. How do I ensure this?

Thanks,

Péter




More information about the Stackless mailing list