id	summary	reporter	owner	description	type	status	priority	component	severity	resolution	keywords	cc
36	PyYaml and WebWare Don't Play Nicely...	stef@…	xi	"Hello,
   Sorry to ask a stupid question, but, is PyYaml thread-safe ? I am trying to run PyYaml under WebWare and I get a session identifier. Due to the nature of WebWare being servlet based, I find that it sometimes calls 'get session' more than once during the lifetime of processing the servlet. The code that get's run more than once is;
{{{
#!python
    def __getitem__(self, key):
        if debug:
            print '>> get (%s)' % key
        filename = self.filenameForKey(key)
        self._lock.acquire()
        try:
            try:
                file = open(filename)
            except IOError:
                raise KeyError, key
            try:
                try:
                    item = yaml.load(file)
                finally:
                    file.close()
            except:                 # session can't be unpickled
                os.remove(filename) # remove session file
                print ""Error loading session from disk:"", key
                self.application().handleException()
                raise KeyError, key
        finally:
            self._lock.release()
        return item
}}}
    When I put wrapper print statements around the yaml.load, I notice that the first time it works without fail, the next time I get this;
{{{
#!python
>> get (20061016171933-d0e40d4c65b62dffbbe4c3d2b21922a5)
 RIGHT BEFORE YAML.load for <open file '/usr/local/web_work/Sessions/20061016171933-d0e40d4c65b62dffbbe4c3d2b21922a5.ses', mode 'r' at 0xb71798d8> (/usr/local/web_work/Sessions/20061016171933-d0e40d4c65b62dffbbe4c3d2b21922a5.ses)
[Mon Oct 16 17:20:28 2006] [error] WebKit: Error while executing script /usr/local/web_work/Compass/RebookHotelPage.py
Traceback (most recent call last):
  File ""/usr/local/webware-cvs/WebKit/Application.py"", line 436, in dispatchRawRequest
    self.runTransaction(trans)
  File ""/usr/local/webware-cvs/WebKit/Application.py"", line 487, in runTransaction
    self.runTransactionViaServlet(servlet, trans)
  File ""/usr/local/webware-cvs/WebKit/Application.py"", line 512, in runTransactionViaServlet
    servlet.runTransaction(trans)
  File ""WebKit/Servlet.py"", line 41, in runTransaction
  File ""/usr/local/webware-cvs/WebKit/Transaction.py"", line 108, in awake
    self._servlet.awake(self)
  File ""/usr/local/web_work/Compass/RebookHotelPage.py"", line 74, in awake
    print "" %s - %s "" % ( self, self.session() )
  File ""WebKit/Page.py"", line 151, in session
  File ""/usr/local/webware-cvs/WebKit/Transaction.py"", line 69, in session
    self._session = self._application.createSessionForTransaction(self)
  File ""/usr/local/webware-cvs/WebKit/Application.py"", line 312, in createSessionForTransaction
    session = self.session(sessId)
  File ""/usr/local/webware-cvs/WebKit/Application.py"", line 279, in session
    return self._sessions[sessionId]
  File ""/usr/local/webware-cvs/WebKit/SessionFileStore.py"", line 59, in __getitem__
    myItem = yaml.load(file)
  File ""build/bdist.linux-i686/egg/yaml/__init__.py"", line 66, in load
  File ""build/bdist.linux-i686/egg/yaml/constructor.py"", line 38, in get_data
  File ""build/bdist.linux-i686/egg/yaml/constructor.py"", line 50, in construct_document
  File ""build/bdist.linux-i686/egg/yaml/constructor.py"", line 393, in construct_yaml_seq
  File ""build/bdist.linux-i686/egg/yaml/constructor.py"", line 120, in construct_sequence
  File ""build/bdist.linux-i686/egg/yaml/constructor.py"", line 96, in construct_object
  File ""build/bdist.linux-i686/egg/yaml/constructor.py"", line 572, in construct_python_object
  File ""build/bdist.linux-i686/egg/yaml/constructor.py"", line 551, in make_python_instance
TypeError: __new__() takes exactly 2 arguments (1 given)
}}}

  So, from my total layman's perspective, it appears that the __init__.py is expected to be called 'once', yet due to WebWare's threading, I think it get's called more than once. Either way, I could be totally and whole heartedly wrong, any ideas ? 

  Priority is 'high' as I am on a strict timeline to understand what's going on, and severity is definitely 'blocker', as without a resolution, WebWare can't use PyYaml. Which, is kinda weird, but, at least in my experience :)

  Regards and Thanks
  Stef"	defect	closed	high	pyyaml	blocker	invalid	pyyaml webware threading	
