我写了一个 django 命令,想看看它的时间,所以在里面django shell_plus
我这样做:
import timeit
from django.core.management import call_command
timeit.timeit("""call_command('prova')""", number=3 )
该命令应运行 3 次并输出其运行时间。
如果直接运行'call_command'它可以工作,如果在timeit内调用它会抛出这个错误:
/usr/lib/python3.5/timeit.py in timeit(self, number)
176 gc.disable()
177 try:
--> 178 timing = self.inner(it, self.timer)
179 finally:
180 if gcold:
/usr/lib/python3.5/timeit.py in inner(_it, _timer)
NameError: name 'call_command' is not defined