Fix to support devappserver2

Note that it will fail with multithreading turned on for tests