def test_get_reloader(self): reloader = get_reloader('example_service.server.standalone', ['example', 'pysoa', 'conformity']) self.assertIsInstance(reloader, _PollingReloader) self.assertEqual('example_service.server.standalone', reloader.main_module_name) self.assertIsNotNone(reloader.watch_modules) self.assertFalse(reloader.signal_forks) reloader = get_reloader('example_service.standalone', [], signal_forks=True) self.assertIsInstance(reloader, _PollingReloader) self.assertEqual('example_service.standalone', reloader.main_module_name) self.assertIsNone(reloader.watch_modules) self.assertTrue(reloader.signal_forks) pysoa.server.autoreload.USE_PY_INOTIFY = True try: reloader = get_reloader('example_service.standalone', [], signal_forks=True) self.assertIsInstance(reloader, _PyInotifyReloader) self.assertEqual('example_service.standalone', reloader.main_module_name) self.assertIsNone(reloader.watch_modules) self.assertTrue(reloader.signal_forks) finally: pysoa.server.autoreload.USE_PY_INOTIFY = False
def _run_server_reloader_wrapper(args, server_class): if args.use_file_watcher is False: # The actual value False means that the option was not specified # Do not check for None, which is false-y, because that means it was specified for all modules _run_server(args, server_class) else: # We have to get the main module name, but the actual name (like example_service.standalone), not '__main__' # If IPython PDB set_trace() occurs before this, it will break __main__ and this won't work # This is, unfortunately, the only way to get the real main module name # noinspection PyUnresolvedReferences,PyPackageRequirements import __main__ module_name = None if hasattr(__main__, '__loader__'): module_name = getattr(__main__.__loader__, 'name', None) or getattr(__main__.__loader__, 'fullname', None) if module_name == '__main__': # If the name is still __main__, this means Python was called without the -m module_name = '' from pysoa.server import autoreload autoreload.get_reloader( module_name or '', args.use_file_watcher, signal_forks=args.fork_processes > 1 ).main( _run_server, (args, server_class), )