On Mar 11, 8:35 am, "Janto Dreijer" <[EMAIL PROTECTED]> wrote: > On Mar 11, 3:27 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> > wrote: > > At least, the problem of using the same generator from different threads > > still remains, if you don't use my modified code. In general, when using > > multiple threads you always need some way to syncronize access to shared > > objects. You are lucky with Sessions because append is an atomic operation > > on lists; for more information see > > http://effbot.org/pyfaq/what-kinds-of-global-value-mutation-are-threa... > > Again you're right. But even putting a try-except:return around the > random.choice still manages to break the interpreter. I'm not looking > for any meaningful output really. I just want it not to break.
I think you need to clarify what you mean by "break". Python tries to prevent C-level corruption (segfaults, etc), but does NOT attempt to prevent python-level corruption. The python-level corruption will *probably* be localized (and the objects involved could be deleted, no harm done), but there's no guarantee that they won't involve some global too. But the examples you give involve C-level corruption. They're not using some low-level interface either, so they're genuine bugs. login1 did segfault for me, but the output is random and usually very long. login2 is somewhat random as well, but much shorter and to the point: Exception exceptions.SystemError: '../Python/traceback.c:96: bad argument to internal function' in <generator object at 0xa7956aec> ignored Exception exceptions.SystemError: '../Python/traceback.c:96: bad argument to internal function' in <generator object at 0xa79569ac> ignored Exception exceptions.SystemError: '../Python/traceback.c:96: bad argument to internal function' in <generator object at 0xa795656c> ignored Exception exceptions.SystemError: '../Python/traceback.c:96: bad argument to internal function' in <generator object at 0xa795ebec> ignored Segmentation fault Blah! I was trying to trace it down, but then the phase of the moon changed and login2 (as well as my variations therein) stopped failing. login1 still segfaults though. And login1 does sometimes give me that weird restricted mode error, so you're not alone. I do remember reading something about generators having a pointer to the thread they're created in, and having problems when migrated between threads. I don't have time to find the posts or bug reports right now, but at least that gives you something to look for (before filing a bug report). Actually, I have a few more minutes. http://mail.python.org/pipermail/python-dev/2006-October/069470.html http://sourceforge.net/tracker/index.php?func=detail&aid=1579370&group_id=5470&atid=105470 That refers to a generator crash. You are using generators, but also getting a weird dict error. Maybe related, maybe not. I'll figure out if I've got a "fixed" version or not when I get back. -- http://mail.python.org/mailman/listinfo/python-list