tornado periodiccallback在第二次运行时失败

时间:2018-04-17 17:30:22

标签: python tornado

我试图让几个PeriodicCallback来监控服务器的不同部分,但是当我运行服务器时,它似乎第一次运行PeriodicCallback但是那个,我在下一个间隔期间得到了跟随错误

File "/usr/local/lib/python3.6/site-packages/tornado/ioloop.py", line 830, in _run self.callback() TypeError: 'NoneType' object is not callable

当服务器正在运行时start_scheduler正在执行server.py。为什么我在第二次运行时遇到此错误PeriodicCallback

MonitorManager

class MonitorManager:

    instance = None

    @classmethod
    def get_instance(cls):
        if not cls.instance:
            cls.instance = cls()
        return cls.instance



    def __init__(self):

        self.node_scheduler = tornado.ioloop.PeriodicCallback(
            self.test(),
            1000*100)

    def test(self):
        print('done')

server.py

class SchedulerServer:

    VERSION = 'v1'

    singleton = None

    def __init__(self, scheduler_instance, monitor_instance):
        # Start scheduler
        self.scheduler_manager = scheduler_instance
        self.monitor_manager = monitor_instance

        self.tornado_settings = dict(
            debug=settings.DEBUG,
            static_path=settings.STATIC_DIR_PATH,
            template_path=settings.TEMPLATE_DIR_PATH,
            scheduler_manager=self.scheduler_manager,
            monitor_manager=self.monitor_manager
        )

        # Setup server
        URLS = [
            # Index page
            (r'/', index_page.Handler)
        ]
        self.application = tornado.web.Application(URLS, **self.tornado_settings)

    def start_scheduler(self):
        self.monitor_manager.start()
        self.scheduler_manager.start()

    def stop_scheduler(self):
        self.scheduler_manager.stop()

    @classmethod
    def run(cls):
        if not cls.singleton:

            cls.singleton = cls(
                scheduler_manager.SchedulerManager.get_instance(),
                monitor_manager.MonitorManager.get_instance()
            )
            cls.singleton.start_scheduler()

            cls.singleton.application.listen(settings.HTTP_PORT, settings.HTTP_ADDRESS)
            tornado.ioloop.IOLoop.instance().start()

1 个答案:

答案 0 :(得分:1)

import { Component } from "@angular/core"; import { DatePickerComponent } from "@progress/kendo-angular-dateinputs"; @Component({ selector: "app-your-component", templateUrl: "./yourComponent.component.html", }) export class YourComponent {} (DatePickerComponent as any).prototype.toggleFocus = function() {}; 来电时出错。 PeriodicCallback需要callback作为第一个参数,但这里

PeriodicCallback

直接调用self.node_scheduler = tornado.ioloop.PeriodicCallback( self.test(), 1000*100) ,会打印self.test()并返回done,并保存此None以供将来使用None。 实际上,第一次执行PeriodicCallback时出错,而不是第二次执行。

要修复它,请传递给PeriodicCallback任何可调用对象,例如PeriodicCallback

self.test
相关问题