[Stackless] Calling stackless.run() from C code

Richard Tew richard.m.tew at gmail.com
Sun May 10 14:44:33 CEST 2009

On Sat, May 9, 2009 at 9:27 PM, Nelsen, Patrick
<Patrick.Nelsen at spectrumdsi.com> wrote:
> Hi all,
> Currently I'm working on a stackless python 2.6.2 implementation on a single threaded embedded device.  The application running inserts and removes tasklets asynchronously based on hardware callbacks.  I am trying to write a scheduling loop in C that will reinsert tasklets to the run queue and call stackless.run(100).  The problem that I am running into is that _Py_Ticker value never gets reset. This causes every single call to stackless.run(100) after the first call will hit the stackless_interupt_call in ceval.c line 2995, and no more code gets executed.  My scheduling routine is attached in the file my_scheduler.c in the method scheduler_run().  I have been using the test_scheduler.py script to test my module.  I also wrote a test script called test_stackless that mimics the behavior that I'm trying to accomplish.  In addition, I also verified that I got the same result when I moved the test() method to its own module.  I am missing a step in setting up the call to stackless.schedule() in my c code?

You might want to start with checking your reference counting.  If
PyEval_CallFunction returns a Python object, you own that reference.
Adding another to it, means you are leaking.  And not removing the
reference if it is None, means you are leaking it.

There are some embedding examples in the examples project:


More information about the Stackless mailing list