Merge pull request #29 from gutenbergtools/fix_ramsession

improved ramsession patch
fix-service
eshellman 2019-08-19 12:46:26 -04:00 committed by GitHub
commit d5fd0928cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 15 deletions

View File

@ -1,5 +1,5 @@
# will submit a PR to CherryPy project - if it gets merged we can remove it. ESH 8/15/2019
import cherrypy
from cherrypy.lib.sessions import RamSession as cpRamSession
class RamSession(cpRamSession):
@ -8,7 +8,17 @@ class RamSession(cpRamSession):
now = self.now()
try:
for _id, (data, expiration_time) in list(self.cache.items()):
cache_items_copy = self.cache.copy().items()
except RuntimeError as re:
"""Under heavy load, list(self.cache.items()) will occasionally raise this error
for large session caches with message "dictionary changed size during iteration"
Better to pause the cleanup than to let the cleanup thread die.
"""
cherrypy.log(f'Runtime Error happened while copying the cache entries: {re}')
cherrypy.log('Ref: https://github.com/cherrypy/cherrypy/pull/1804')
return
for _id, (data, expiration_time) in cache_items_copy:
if expiration_time <= now:
try:
del self.cache[_id]
@ -21,11 +31,6 @@ class RamSession(cpRamSession):
except KeyError:
pass
except RuntimeError:
"""Under heavy load, list(self.cache.items()) will occasionally raise this error
for large session caches with message "dictionary changed size during iteration"
Better to pause the cleanup than to let the cleanup thread die.
"""
return