On Jan 19, 2011, at 10:52 AM, ron_m wrote:
> I saw that too last night but it was late. It would be better to set 
> response.session_file to None which will force a file close since the file 
> object goes out of scope. Adding a del in _unlock will cause AttributeError 
> in the _try_store_on_disk when the request-response cycle is finishing up.

In practice, I don't think so, because the only reason this would happen would 
be through session.forget(), and _try_store_on_disk would never get that far. 
It wouldn't be very robust logic, though, I agree.

If we set response.session_file to None, we'd have to be careful when testing 
it, since session is Storage, so session.session_file is None even if it's not 
defined. We could set it to False, allowing an 'is False' test.

The del (or = None) could be conditional on self._forget. That'd help, because 
it'd guarantee that _try_store_on_disk would return.

   def forget(self, response=None):
        self._forget = True
        self._unlock(response)

   def _unlock(self, response):
       if response and response.session_file:
           try:
               portalocker.unlock(response.session_file)
           except: ### this should never happen but happens in Windows
               pass
           if self._forget:
               response.session_file.close()
               del response.session_file

Reply via email to