Using threading.Lock as context manager

不想你离开。 提交于 2019-12-22 03:43:24

问题


In the documentation of the threading module it says:

All of the objects provided by this module that have acquire() and release() methods can be used as context managers for a with statement. The acquire() method will be called when the block is entered, and release() will be called when the block is exited.

I was wondering if it is called in blocking or non-blocking mode?


回答1:


From looking at the CPython source, it appears that it's called with default arguments, which means in blocking mode.

The methods you want to look at in particular are __enter__(), which is called at the beginning of the with block, and __exit__(), which is called at the end.



来源:https://stackoverflow.com/questions/13290429/using-threading-lock-as-context-manager

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