调用runserver命令后调用函数

2024-09-30 20:23:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个django应用程序,它有自己的模型和视图。当我用python manage.py runserver启动django服务器时,我想打开一个matlab实例,在那里预加载环境,并将这个实例发送给每个请求。我该怎么做? 您可以假设我有一个用于python的matlab包装器:

class MatlabWrapper(object):
    def __init__(self):
        ...

    def run(self):
        ...

    def execute(self, cmd):
        ...

    def exit(self):
        ...

# usage
m = MatlabWrapper()
m.run() # launch matlab
m.execute(cmd1) # execute command 1
m.execute(cmd2) # execute command 2

Tags: django实例runpy模型self视图应用程序