Python `schedule` 计划任务的返回值去哪里了? [英] Where does a Python `schedule` scheduled task's return value go?
问题描述
我有一个使用 schedule 库运行的计划任务.我的任务的返回值去哪里了?返回 True
与返回 False
的效果不同吗?
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
?
示例:
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()
将简单地增加 False
引用的任何对象的引用计数,以反映 a
现在也对同一对象的引用.
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.
在没有任何此类分配的情况下,如
In the absence of any such assignment, like with
foo()
引用计数不会增加.如果对该值的唯一其他引用是 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.
这篇关于Python `schedule` 计划任务的返回值去哪里了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!