为什么这会测试线程的所有权

时间:2019-07-17 11:41:31

标签: python python-3.x multithreading

当我在threading.py模块的类条件部分中阅读源代码时,我的想法是:如果锁归current_thread.self.self .__ lock.acquire(0)拥有,除非它本身失败,否则返回false。锁定

def _is_owned(self):                                                                                                                                                               
  # Return True if lock is owned by current_thread.                                                                                                                              
  # This method is called only if __lock doesn't have _is_owned().                                                                                                               
  if self.__lock.acquire(0):                                                                                                                                                     
      self.__lock.release()                                                                                                                                                      
      return False                                                                                                                                                               
  else:                                                                                                                                                                          
      return True

0 个答案:

没有答案