Favicon
Gravatar

stackless bug fix

I’ve just fixed a bug where the data sent over a channel could get lost, being replaced with a “None”.

This could happen if channel action, tasklet deletion and stack spilling all happened at once J

See

http://blog.ccpgames.com/kristjan/

for details.

 

K

_______________________________________________
Stackless mailing list
Stackless@...
http://www.stackless.com/mailman/listinfo/stackless
Sylvain Prat | 20 May 00:29
Picon
Gravatar

Tasklet cleanup?

Hello,

I'm wondering how tasklets can clean themselves up when they are
destroyed due to garbage collection (i.e. when they are not in the
runnables and not referenced by any object anymore). Greenlet solves
this problem by raising a GreenletExit exception in the greenlet's run
function when the greenlet is about to die due to garbage collection.
However, in stackless, it seems that no TaskletExit exception is
raised when the tasklet is about to die, so we can't simply use a
try/finally in the tasklet's callable to clean up resources.

I tried to wrap my tasklet in a parent object which has the same
lifespan as my tasklet and has a __del__ function for cleaning up, but
I keep having problems with circular references (the wrapper/parent
object also provides the callable of the tasklet, i.e. a bound method)
that make the tasklet/parent object uncollectable (circular references
: wrapper --> tasklet --> stackless machinery? --> callable stack
frame (bound method of wrapper) --> wrapper). Same problem when trying
to inherit from tasklet.

So, how can I clean up resources in tasklets? (I'm pretty sure I've
missed something obvious)

Thank in advance,
Sylvain

--

-- 
Sylvain PRAT
Fernando Miranda | 10 May 22:11
Picon

Is the Stackless website down?

I cannot reach the website from Buenos Aires. It's just me?
Adam Preble | 6 May 12:25
Picon

Using Stackless Python to overcome GIL issues interoperating with a C++ runtime

I wondered if anybody here has used Stackless Python in some clever ways to work around the global interpreter lock.  I have some C++ objects wrapped with Boost.Python, and I run into some interesting stuff when I start implementing interfaces defined in these wrappers in Python.  At that point I have to do some work that involves acquiring the GIL to run the Python version of the code whenever I'm running into it from the C++ side in other threads.  This normally works okay until I get into situations like this:


1. Python interpreter calls something with a wrapper into C++.
2. C++ code calls back into a Python implementation of a C++ interface (GIL involved here).
3. Python implementation calls some other thing wrapped from C++ . . . note that step #1 hasn't actually completed yet.
4. C++ code calls back into Python.  Here we deadlock trying to get the GIL.

I'm looking at a situation here where I need to place all these pending GIL-related operations on some common stack, and have something comb over them.  When that comber realizes it already took the GIL, and it's being told to do a new operation, it can at least do some negotiation with itself.  I don't know how the GIL works entirely here since I haven't implemented this logic yet, but it's clear I have to do something.  At the worst I assume I will have to save the interpreter stack from the prior call before moving on to the next call.

It occurred to me there could be some nice ways to do this with coroutines.  I'm already pondering some stuff Boost has for coroutines that might make this a lot less ugly, but I wondered if Stackless had something that could come to the rescue.  I don't know what it could possibly be, but I thought I'd ask the list for advice.

_______________________________________________
Stackless mailing list
Stackless@...
http://www.stackless.com/mailman/listinfo/stackless
Fernando Miranda | 29 Apr 08:09
Picon

Tasklet clean up

Hello, I'm not sure if this has sense but I'm wondering if Stackless
'clean ups' all tasklet resources when tasklets die.
For example, suposse a tasklet that opens files and/or sockets, will
those resources be automatically  closed when the tasklet die? Can
that be done easily?

Thanks in advance.
Favicon
Gravatar

channels and StopIteration

So,

Channels objey the iterator protocol.  calling channel.close() will raise the StopIteration exception from the channel.__next__ method.

But, calling channel.close() from the receiving end will also cause this same exception to be raised when someone wants to call channel.send().

Now, I wonder if a more appropriate exception for the send() call wouldn‘t be GeneratorExit()?    This is what the generator yield(foo) statement raises when the generator is closed, and it seems logical that this should be the exception raised when someone tries to send to a closed channel.

 

K

_______________________________________________
Stackless mailing list
Stackless@...
http://www.stackless.com/mailman/listinfo/stackless
Gil Colgate | 9 Apr 20:43
Picon

Patch to exception handler.

Here is a fix for the exception handler, I included just the .patch.

    This corrects the problems with python having a different exception the environment when the item is called again.
   
    In the previous code, whenever a python tasklet was suspended the top of the exception chain was saved. This very well could be a pointer into code above the python stack into the main program. When the python tasklet is called again, it's stack is put back *in the same place*, but the environment above the stack *might be different*. This would cause the exception chain to screw up in the part where the exception chain points above the stack. This was the cause of the broken exception chain bug.
   
     
    If a tasklet has none of it's own exception chains, we will discover this by reading the exception list and seeing that the address is above the stack, so we don't need to save or restore it it.
   
    If, on the other hand, the tasklet has a chain we save it. When restoring it we look at the current chain and insert the chain from the restored stack into it at the appropriate spot, so that the tasklet's chain points correctly into it's parent's change.
   
    Stack slicing: Stackless in general has a problem with stack slicing. This code will work in when the stack is sliced (I tested it with 2K stack slices and try-catches everywhere) but certain exceptions that belonged to inactive stack slices will not be executed since they are not currently linked into the chain. 

Attachment (stacklesseval.c.patch): application/octet-stream, 6370 bytes
_______________________________________________
Stackless mailing list
Stackless@...
http://www.stackless.com/mailman/listinfo/stackless
Favicon
Gravatar

http://www.stackless.com/pipermail/stackless/2007-April/000142.html

I wonder,

Why does stackless redefine PyHeapTypeObject?

Is there any reason to?  Can we fix that so that compatibility with stuff such as PyQT is maintained?

 

K

_______________________________________________
Stackless mailing list
Stackless@...
http://www.stackless.com/mailman/listinfo/stackless
Gil Colgate | 3 Apr 18:28
Picon

Exception handling crashes, how to contribute

I had the unfortunate experience of mixing python and C++ code on the Windows environment on a large program with multiple libraries not written by me.

The C++ code uses the structured exception handling protocol, and stackless does no properly handle this. This could result in crashes in the following way:

Whenever a python tasklet is suspended the top of the exception chain is saved by stackless. This very well could be pointing into code above the python stack into the main program. When the python tasklet is called again, it's stack is put back *in the same place*, but the environment above the stack *might be different*. This would cause the exception chain to screw up in the part where the exception chain points above the stack.

This would cause a crash on an exception... for example a function uses OutputDebugStr (which routes by using an exception).... the exception handler itself could crash.

I have corrected this issue in my local copy of Stackless.. it involves changes to stacklesseval.c and involves patching the exception chain properly when tasklet switching, in cases when windows structured execption handling is defined.  I have not contributed to stackless open source before, but I think anyone else getting peculiar crashes with exceptions on Windows might appreciate this fix.

I would like someone to explain the procedure to contribute to me.
   

_______________________________________________
Stackless mailing list
Stackless@...
http://www.stackless.com/mailman/listinfo/stackless
Favicon
Gravatar

tasklet.set_atomic

Hi there.

Working on stuff to spawn off work for actual worker threads, I realized that there was no good way to to synchronize between two tasklets on two threads.

That is to say:

When sending data between two tasklet on the same thread, usually it is sufficient to use tasklet.set_atomic() to disable tasklet interrupts (that rarely happen anyway, only when using stackless.run() with non-zero values) to ensure atomicity.

For example, this code from stacklesslib.locks.Event:

 

def wait(self, timeout=None):

        with atomic():

            if self._is_set:

                return True

            lock_channel_wait(self.chan, timeout)

            return self._is_set

 

    def set(self):

        with atomic():

            self._is_set = True

            for i in range(-self.chan.balance):

                self.chan.send(None)

 

the atomic() context manager is used here to ensure consistency of state.

 

However, I realized that when using the Event to set or wait for events between threads, that is, when one tasklet was waiting and another, on a different thread, was setting the event, this approach doesn‘t work.  A thread switch can happen anywhere, for example, in wait after the initial _is_set test, but before the wait, causing a lost wakeup bug.

 

The solution is to make „atomic“ also suspend automatic thread switching while in progress.  I‘ve implemented this for our patched CCP version of stackless and wanted to mention this here before rolling it into the distribution.  One thing that only slightly worries me is that this approach assumes a GIL-like implementation.  But stackless being so specialized, we are unlikely to see a non-GIL version any time soon J

 

K

_______________________________________________
Stackless mailing list
Stackless@...
http://www.stackless.com/mailman/listinfo/stackless
Richard Shea | 2 Apr 12:00

Stackless co-existence with CPython - does this email still hold ?

I'm interested in installing Stackless on a Ubuntu VM I have (8.04).

In this email ...

http://www.stackless.com/pipermail/stackless/2008-April/003424.html

... issues are discussed with a stackless installation making future use
of the the pre-existing CPython installation problematic (specifically
the common use of the PYTHONPATH environment variable).

Given that email is four years old I wondered if things had changed
and/or someone had a suggestion for completely isolating stackless ?

regards

Richard.

Gmane