On Mar 11, 1:46 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Sun, 11 Mar 2007 07:32:04 -0300, Janto Dreijer <[EMAIL PROTECTED]> > escribió: > > > > > I have been having problems with the Python 2.4 and 2.5 interpreters > > on both Linux and Windows crashing on me. Unfortunately it's rather > > complex code and difficult to pin down the source. > > > So I've been trying to reduce the code. In the process it's started to > > crash in different ways. I'm not sure if any of it is related. The > > following is only crashing Python 2.5 (r25:51908, Sep 19 2006, > > 09:52:17) [MSC v.1310 32 bit (Intel)] on win32 in two different(?) > > ways. > > > ==================== > > > Using the login1() function will throw a bunch of exceptions the most > > interesting of which is: > > > Exception in thread Thread-34: > > Traceback (most recent call last): > > File "C:\Python25\lib\threading.py", line 460, in __bootstrap > > self.run() > > File "C:\Python25\lib\threading.py", line 440, in run > > self.__target(*self.__args, **self.__kwargs) > > File "Copy of scratchpad.py", line 20, in login1 > > random.choice(System.sessions).session_iter.next() > > RuntimeError: instance.__dict__ not accessible in restricted mode > > From the error message, you appear to be using some form of restricted > execution - RExec or similar. I didn't try that way, but using the normal > mode, I got this different exception instead (using login1): > > Exception in thread Thread-85: > Traceback (most recent call last): > File "c:\apps\python\lib\threading.py", line 460, in __bootstrap > self.run() > File "c:\apps\python\lib\threading.py", line 440, in run > self.__target(*self.__args, **self.__kwargs) > File "crash.py", line 20, in login1 > random.choice(System.sessions).session_iter.next() > ValueError: generator already executing > > It appears to indicate that you must syncronize the generators. > Adding a Lock object to Session appears to work OK: > > class Session: > def __init__(self): > self.lock = Lock() > self.session_iter = session_iter(self) > > def login1(): > # first interpreter > System.sessions.append(Session()) > while 1: > session = random.choice(System.sessions) > session.lock.acquire() > session.session_iter.next() > session.lock.release() > > Your login2 version does not generate any error on my PC. > > -- > Gabriel Genellina
As far as I can tell I'm not running it from restricted mode explicitly. The reason I'm doing the random.choice() is so I don't have a handle ("session" in this case) that would prevent it from being garbage collected. I am not bothered by the Python-level Exceptions. I am bothered by the interpreter throwing a segfault. What I suspect is happening is the Session object is deallocated, while it still has a reference from within the iterator. It's quite difficult to reproduce these bugs consistently. You might need to run it a few times.
-- http://mail.python.org/mailman/listinfo/python-list