【发布时间】:2017-06-28 18:48:29
【问题描述】:
【问题讨论】:
【问题讨论】:
我不这么认为。如果我正确读取源代码,则通过查找模块从 CLI 中发现命令:
https://github.com/django/django/blob/master/django/core/management/init.py#L26
收集使用:
https://docs.python.org/2/library/pkgutil.html#pkgutil.iter_modules
【讨论】:
您可以在一个文件中编写多个命令。请按照以下步骤操作
from django.core.management.base import BaseCommand
from subprocess import Popen
from sys import stdout, stdin, stderr
import time
import os
import signal
class Command(BaseCommand):
help = 'Run all commands'
commands = [
'python manage.py schedule',
'python manage.py runserver'
]
def handle(self, *args, **options):
proc_list = []
for command in self.commands:
print("$ " + command)
proc = Popen(command, shell=True, stdin=stdin,
stdout=stdout, stderr=stderr)
proc_list.append(proc)
try:
while True:
time.sleep(10)
except KeyboardInterrupt:
for proc in proc_list:
os.kill(proc.pid, signal.SIGKILL)
python manage.py mycommand
这个link 帮助了我。
【讨论】: