def dispatch(self): """Dispatch a request and postprocess.""" # TODO(mbarbella): Delete this once the Python 3 migration is complete. @future_utils.as_native_str() def to_native_str(text): """Convert from future's newstr to a native str.""" return text if environment.get_value('PY_UNITTESTS'): # Unit tests may not have NDB available. super(Handler, self).dispatch() else: with ndb_init.context(): super(Handler, self).dispatch() # App Engine Python 2 does not like it when there are threads still alive # at the end of a request. In particular, NDB and gRPC may create threads # which aren't automatically stopped at this point due to reference # cycles. Garbage collect here to get rid of them. # TODO(ochang): Check if this is still needed for Python 3 GAE. gc.collect() # Replace header values with Python 2-style strings after dispatching. There # is an explicit type check against str that causes issues with newstr here. for key, value in self.response.headers.items(): self.response.headers[key] = to_native_str(value)
def dispatch(self): """Dispatch a request and postprocess.""" if environment.get_value('PY_UNITTESTS'): # Unit tests may not have NDB available. super(Handler, self).dispatch() else: with ndb_init.context(): super(Handler, self).dispatch()
def setUpClass(cls): """Class setup.""" for emulator_name in emulator_names: if emulator_name not in _emulators: _emulators[emulator_name] = start_cloud_emulator(emulator_name) atexit.register(_emulators[emulator_name].cleanup) if emulator_name == 'datastore': cls._context_generator = ndb_init.context() cls._context_generator.__enter__() super(Wrapped, cls).setUpClass()
def run_testcase_and_return_result_in_queue(crash_queue, thread_index, file_path, gestures, env_copy, upload_output=False): """Run a single testcase and return crash results in the crash queue.""" # Since this is running in its own process, initialize the log handler again. # This is needed for Windows where instances are not shared across child # processes. See: # https://stackoverflow.com/questions/34724643/python-logging-with-multiprocessing-root-logger-different-in-windows logs.configure('run_testcase', { 'testcase_path': file_path, }) # Also reinitialize NDB context for the same reason as above. with ndb_init.context(): _do_run_testcase_and_return_result_in_queue( crash_queue, thread_index, file_path, gestures, env_copy, upload_output=upload_output)
return environment.set_bot_environment() persistent_cache.initialize() logs.configure('run') # Create command strings to launch bot and heartbeat. base_directory = environment.get_startup_scripts_directory() log_directory = environment.get_value('LOG_DIR') bot_log = os.path.join(log_directory, 'bot.log') bot_script_path = os.path.join(base_directory, BOT_SCRIPT) bot_interpreter = shell.get_interpreter(bot_script_path) assert bot_interpreter bot_command = '%s %s' % (bot_interpreter, bot_script_path) heartbeat_script_path = os.path.join(base_directory, HEARTBEAT_SCRIPT) heartbeat_interpreter = shell.get_interpreter(heartbeat_script_path) assert heartbeat_interpreter heartbeat_command = '%s %s %s' % (heartbeat_interpreter, heartbeat_script_path, bot_log) run_loop(bot_command, heartbeat_command) logs.log('Exit run.py') if __name__ == '__main__': with ndb_init.context(): main()