本文整理汇总了Python中django.utils.autoreload.run_with_reloader方法的典型用法代码示例。如果您正苦于以下问题:Python autoreload.run_with_reloader方法的具体用法?Python autoreload.run_with_reloader怎么用?Python autoreload.run_with_reloader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.autoreload
的用法示例。
在下文中一共展示了autoreload.run_with_reloader方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from django.utils import autoreload [as 别名]
# 或者: from django.utils.autoreload import run_with_reloader [as 别名]
def handle(self, *args, **options):
self.stdout.write("Starting celery worker with autoreload...")
autoreload.run_with_reloader(restart_celery, args=None, kwargs=None)
示例2: handle
# 需要导入模块: from django.utils import autoreload [as 别名]
# 或者: from django.utils.autoreload import run_with_reloader [as 别名]
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)
示例3: handle
# 需要导入模块: from django.utils import autoreload [as 别名]
# 或者: from django.utils.autoreload import run_with_reloader [as 别名]
def handle(self, *args, **options):
print('Starting celery worker with autoreload...')
autoreload.run_with_reloader(restart_celery)
示例4: handle
# 需要导入模块: from django.utils import autoreload [as 别名]
# 或者: from django.utils.autoreload import run_with_reloader [as 别名]
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)
示例5: test_swallows_keyboard_interrupt
# 需要导入模块: from django.utils import autoreload [as 别名]
# 或者: from django.utils.autoreload import run_with_reloader [as 别名]
def test_swallows_keyboard_interrupt(self, mocked_get_reloader):
mocked_get_reloader.side_effect = KeyboardInterrupt()
autoreload.run_with_reloader(lambda: None) # No exception
示例6: test_calls_sys_exit
# 需要导入模块: from django.utils import autoreload [as 别名]
# 或者: from django.utils.autoreload import run_with_reloader [as 别名]
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)
示例7: test_calls_start_django
# 需要导入模块: from django.utils import autoreload [as 别名]
# 或者: from django.utils.autoreload import run_with_reloader [as 别名]
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]
)
示例8: handle
# 需要导入模块: from django.utils import autoreload [as 别名]
# 或者: from django.utils.autoreload import run_with_reloader [as 别名]
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()