These are chat archives for cherrypy/cherrypy

21st
Aug 2017
Andrew Schamp
@schamp
Aug 21 2017 19:06

I'm running into something unexpected with FileSession and cherrypy.session.locking = 'explicit'. I have a number of streaming responses that take a long time, and so I wanted to manage the session locks by hand so they wouldn't block for each other. However, with session.locking as 'explicit', the automatic 'session._save' that occurs in the 'before_finalize' hook complains: AssertionError: The session was saved without being locked. Check your tools' priority levels.

This appears to be because of the hooks.attach('before_finalize', _sessions.save) in _cptools.py:316.

So it appears that the session has to be locked before this part of the request runs. If this is intentional, it's not clear from the documentation why. Is this intentional? Am I missing something about the way I should be handling my session data (locking before use, unlocking after)? If locking is explicit, should the 'before_finalize' save hook do it's own lock, or is that a bad idea?

Andrew Schamp
@schamp
Aug 21 2017 19:15
the only thing I could figure out to make it work was to hack two tools in, one in before_finalize that locks the session for the save call, and another in on_end_resource that unlocks it. It seems to work. But I worry I'm missing something that will come back to bite me if I do this, there ought to be a better way.