app.add_processor(web.loadhook(session_hook))3,解决sae环境中无法读写本地目录问题SAE环境下python无法对本地目录进行读写操作,但sae提供了Storage,并且可以将Storage像本地磁盘一样挂载使用.所以添加如下代码:monkey.patch_all() session_root = "/s/session/"注意:需要提前在sae中启用Storage,且添加"domain:session"以便具有权限.4,解决SEA的Storage作为磁盘挂载后但不支持os.remove方法"目前支持(patch)的文件系统接口函数为: open, os.listdir, os.mkdir, os.path.exists, os.path.isdir, os.open, os.fdopen, os.close, os.chmod, os.stat, os.unlink, os.rmdir"但webpy在DiskStore.cleanup方法却是调用的os.remove,需要改为os.unlink#因新浪SAE的stroge不支持挂载为路径后的os.remove函数,故重新改在一下 class DiskStore(web.session.DiskStore): def __init__(self, root): web.session.DiskStore.__init__(self, root) # if the storage root doesn"t exists, create it. self.root = root
def cleanup(self, timeout): now = time.time() for f in os.listdir(self.root): path = self._get_path(f) atime = os.stat(path).st_atime if now - atime > timeout : os.unlink(path)#改写为unlink函数OK,现在session已经可以正常使用了.本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-01/111179.htm