简体   繁体   English

Python `schedule` 计划任务的返回值去哪里了?

[英]Where does a Python `schedule` scheduled task's return value go?

I have a scheduled task that runs using the schedule library.我有一个使用计划库运行的计划任务。 Where does the return value of my task go?我的任务的返回值去哪里了? Does returning True have a different effect than returning False ?返回True与返回False有不同的效果吗?

Example:例子:

def foo():
    return False

schedule.every().day.do(foo)
while True:
    schedule.run_pending()
    time.sleep(1)

It doesn't "go" anywhere.它不会“去”任何地方。 Every object has a reference count, and a call like每个对象都有一个引用计数,和一个像

a = foo()

would simply increment the reference count of whatever object False refers to, to reflect that a is now also an reference to the same object.将简单地增加False引用的任何对象的引用计数,以反映a现在也是对同一对象的引用。

In the absence of any such assignment, like with在没有任何此类分配的情况下,例如

foo()

the reference count simply is not incremented.引用计数根本不增加。 If the only other reference to the value was a name local to foo , then the object would be subject to garbage collection.如果对该值的唯一其他引用是foo本地名称,则该对象将受到垃圾收集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM