Python django.utils.autoreload.run_with_reloader() Examples
The following are 8
code examples of django.utils.autoreload.run_with_reloader().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.utils.autoreload
, or try the search function
.
Example #1
Source File: celery_autoreload.py From django-starter-project with MIT License | 5 votes |
def handle(self, *args, **options): self.stdout.write("Starting celery worker with autoreload...") autoreload.run_with_reloader(restart_celery, args=None, kwargs=None)
Example #2
Source File: graphql_schema.py From graphene-django with MIT License | 5 votes |
def handle(self, *args, **options): options_schema = options.get("schema") if options_schema and type(options_schema) is str: module_str, schema_name = options_schema.rsplit(".", 1) mod = importlib.import_module(module_str) schema = getattr(mod, schema_name) elif options_schema: schema = options_schema else: schema = graphene_settings.SCHEMA out = options.get("out") or graphene_settings.SCHEMA_OUTPUT if not schema: raise CommandError( "Specify schema on GRAPHENE.SCHEMA setting or by using --schema" ) indent = options.get("indent") watch = options.get("watch") if watch: autoreload.run_with_reloader( functools.partial(self.get_schema, schema, out, indent) ) else: self.get_schema(schema, out, indent)
Example #3
Source File: celery.py From wharf with GNU Affero General Public License v3.0 | 5 votes |
def handle(self, *args, **options): print('Starting celery worker with autoreload...') autoreload.run_with_reloader(restart_celery)
Example #4
Source File: grpcserver.py From django-grpc with MIT License | 5 votes |
def handle(self, *args, **options): if options['autoreload'] is True: self.stdout.write("ATTENTION! Autoreload is enabled!") if hasattr(autoreload, "run_with_reloader"): # Django 2.2. and above autoreload.run_with_reloader(self._serve, **options) else: # Before Django 2.2. autoreload.main(self._serve, None, options) else: self._serve(**options)
Example #5
Source File: test_autoreload.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_swallows_keyboard_interrupt(self, mocked_get_reloader): mocked_get_reloader.side_effect = KeyboardInterrupt() autoreload.run_with_reloader(lambda: None) # No exception
Example #6
Source File: test_autoreload.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_calls_sys_exit(self, mocked_restart_reloader): mocked_restart_reloader.return_value = 1 with self.assertRaises(SystemExit) as exc: autoreload.run_with_reloader(lambda: None) self.assertEqual(exc.exception.code, 1)
Example #7
Source File: test_autoreload.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_calls_start_django(self, mocked_reloader, mocked_start_django): mocked_reloader.return_value = mock.sentinel.RELOADER autoreload.run_with_reloader(mock.sentinel.METHOD) self.assertEqual(mocked_start_django.call_count, 1) self.assertSequenceEqual( mocked_start_django.call_args[0], [mock.sentinel.RELOADER, mock.sentinel.METHOD] )
Example #8
Source File: process_queue.py From zulip with Apache License 2.0 | 4 votes |
def handle(self, *args: Any, **options: Any) -> None: logging.basicConfig() logger = logging.getLogger('process_queue') def exit_with_three(signal: int, frame: FrameType) -> None: """ This process is watched by Django's autoreload, so exiting with status code 3 will cause this process to restart. """ logger.warning("SIGUSR1 received. Restarting this queue processor.") sys.exit(3) if not settings.USING_RABBITMQ: # Make the warning silent when running the tests if settings.TEST_SUITE: logger.info("Not using RabbitMQ queue workers in the test suite.") else: logger.error("Cannot run a queue processor when USING_RABBITMQ is False!") raise CommandError def run_threaded_workers(queues: List[str], logger: logging.Logger) -> None: cnt = 0 for queue_name in queues: if not settings.DEVELOPMENT: logger.info('launching queue worker thread ' + queue_name) cnt += 1 td = Threaded_worker(queue_name) td.start() assert len(queues) == cnt logger.info('%d queue worker threads were launched', cnt) if options['all']: signal.signal(signal.SIGUSR1, exit_with_three) autoreload.run_with_reloader(run_threaded_workers, get_active_worker_queues(), logger) elif options['multi_threaded']: signal.signal(signal.SIGUSR1, exit_with_three) queues = options['multi_threaded'] autoreload.run_with_reloader(run_threaded_workers, queues, logger) else: queue_name = options['queue_name'] worker_num = options['worker_num'] logger.info("Worker %d connecting to queue %s", worker_num, queue_name) worker = get_worker(queue_name) worker.setup() def signal_handler(signal: int, frame: FrameType) -> None: logger.info("Worker %d disconnecting from queue %s", worker_num, queue_name) worker.stop() sys.exit(0) signal.signal(signal.SIGTERM, signal_handler) signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGUSR1, signal_handler) worker.start()