在bottle.py启动时运行一次函数

pyp*_*pat 8 python scheduling bottle

我有一个瓶子应用程序,我最终不会在apache上部署(只有fyi,如果这很重要).现在我需要在启动瓶子应用程序后运行一次函数.我不能把它放到路由功能中,因为即使没有用户访问过网站也必须运行它.

这样做有什么好的实践吗?

该函数启动APScheduler实例并向其添加一个jobstore.

f p*_*f p 0

创建一个 APScheduler

查看同一站点中对象使用和创建的示例,因为它太笼统,无法提供具体的示例来复制。

我不知道是否有帮助。

class Shed(object):
    def __init__(self): # this to start it
        # instruccions here

    def Newshed(self, data):
        # Call from bottle

    # more methods ...


...

# init
aps = Shed() # this activates Shed.__init__()

...

# in the @router
x = aps.Newshed(data)  # or whatever
Run Code Online (Sandbox Code Playgroud)

无论如何,我仍在学习这些东西,这只是一个想法。