tornado periodiccallback在第二次运行时失败

2024-04-19 01:41:34 发布

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

不过,在接下来的cdm>服务器运行的第一个时间段中,{1>似乎是不同的

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

当服务器正在运行时,server.py中的start_scheduler正在执行。为什么我在第二次运行PeriodicCallback时得到这个错误?在

监控管理器

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')

服务器.py

^{2}$

Tags: instancepytestself服务器defnottornado
1条回答
网友
1楼 · 发布于 2024-04-19 01:41:34

PeriodicCallback调用出错。PeriodicCallback需要一个{a1}作为第一个参数,但是这里

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

有一个直接调用self.test(),它打印done并返回{},这个{}被保存起来以备将来使用{}。 所以实际上,第一次执行PeriodicCallback时出错,而不是第二次。在

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

^{pr2}$

相关问题 更多 >