Ben Sizer wrote: > On Thursday, 30 April 2015 01:45:05 UTC+1, Chris Angelico wrote: >> On Thu, Apr 30, 2015 at 2:01 AM, Ben Sizer wrote: >> > 1) There clearly is a module named OMDBMap, and it's importable - it's >> > there in the 2nd line of the traceback. >> > >> > Does anybody have any suggestions on how I can go about debugging this? >> > Or refactoring it to avoid whatever is happening here? >> >> Are you half way through importing it when this load() call happens? >> That might cause some issues. > > No, we already imported OMDBMap at the top of OMDBSetup. > >> Has your current directory been changed anywhere in there? > > Good question. It turns out that the current directory seems to be $HOME > when loading, but is the script directory during saving. This will be > because the Linux server is running under mod_wsgi, whereas we run the > save script in-place. Our Windows and Mac tests run via Flask's built-in > server so the working directory is likely to be the same whether we're > running the script that does pickle.dump or the whole app that does > pickle.load. > >> What happens if you catch this exception and print out sys.modules at >> that point? > > Another good question, and this gives us the answer. The module lists are > quite different, as I'd expect because the load happens in the context of > the full application whereas the dump happens as a standalone script. But > literally every module that is in the 'before dump' list is in the 'before > load' list - except OMDBMap. Like the error says! What /is/ in the 'before > load' list however is "my_wsgi_app.OMDBMap". The module has been imported, > but the pickle algorithm is unable to reconcile the module in the WSGI > app's namespace with the module referenced in the pickle file. > > So... I don't know how to fix this, but I do now know why it fails, and I > have a satisfactory answer for why it is acting differently on the Linux > server (and that is just because that is the only one running under WSGI). > Two out of three isn't bad!
How about moving OMDBMap.py into the parent folder of my_wsgi_app.__file__ or any other folder in sys.path? -- https://mail.python.org/mailman/listinfo/python-list