threading and iterator crashing interpreter
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sun Mar 11 07:46:58 EDT 2007
En Sun, 11 Mar 2007 07:32:04 -0300, Janto Dreijer <jantod at gmail.com>
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
More information about the Python-list
mailing list