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

ぃ、小莉子 提交于 2020-02-25 04:22:13

问题


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?

Example:

def foo():
    return False

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

回答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.

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.



来源:https://stackoverflow.com/questions/57329502/where-does-a-python-schedule-scheduled-tasks-return-value-go

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!