479.importlib bug workaround by exarkun · Pull Request #498 · gridsync/gridsync
This is an attempt to further mitigate #479. It probably cannot be said that this fixes that issue because any other __del__, weakref callback, or signal handler could still introduce an import at a bad time.
Still, maybe it is worth having until CPython does something about the underlying issue. The change does mean ResourceWarning reporting by pytest will be lost. I don't think that's a big deal because I don't think anyone is paying attention to that information right now anyway (if we wanted GridSync to be ResourceWarning-free then I expect we would add a CI job that configures a warnings filter like "error::ResourceWarning" and this should also avoid the CPython bug).
Also included here is a change to PYTHONDONTWRITEBYTECODE so that it is set consistently for all platforms when using tox instead of only being set for Windows. It was set for Windows because it managed to mitigate the CPython bug but it did so in a more fragile way than this warnings reconfiguration (I think) but it is a pretty reasonable thing to set anyway since pyc files mostly add complexity.