前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python库之threading

python库之threading

作者头像
全栈程序员站长
发布2022-07-18 15:12:31
2830
发布2022-07-18 15:12:31
举报

大家好,又见面了,我是全栈君

  This module constructs higher-level threading interfaces on top of the lower level python库之_threadmodule

  官方参考文档:https://docs.python.org/2/library/threading.html

threading库对象和方法

(1)threading.active_count()

(2)theading.Condition()

  A factory function that returns a new condition variable object,See Condition Objects.

(3)threading.current_thread()

(4)threading.enumerate()

  Return a list of all Thread objects currently alive. The list includes daemonic threads, dummy thread objects created by current_thread(), and the main thread. It excludes terminated threads and threads that have not yet been started.

(5)threading.event()

  A factory function that returns a new event object. An event manages a flag that can be set to true with the set() method and reset to false with the clear() method. The wait() method blocks until the flag is true.See Event Objects.

(6)class threading.local 

   A class that represents thread-local data. Thread-local data are data whose values are thread specific. To manage thread-local data, just create an instance of local (or a subclass) and store attributes on it:

代码语言:javascript
复制
  mydata = threading.local()   mydata.x = 1 

  The instance’s values will be different for separate threads.

  For more details and extensive examples, see the documentation string of the _threading_local module.

(7)theading.Lock()

  A factory function that returns a new primitive lock object. Once a thread has acquired it, subsequent attempts to acquire it block, until it is released; any thread may release it.See Lock Objects.

(8)threading.RLock()

  A factory function that returns a new reentrant lock object. A reentrant lock must be released by the thread that acquired it. Once a thread has acquired a reentrant lock, the same thread may acquire it again without blocking; the thread must release it once for each time it has acquired it.See RLock Objects.

(9)threading.Semaphore([value])

  A factory function that returns a new semaphore object. A semaphore manages a counter representing the number of release() calls minus the number of acquire() calls, plus an initial value. The acquire() method blocks if necessary until it can return without making the counter negative. If not given, value defaults to 1.See Semaphore Objects.

(10)threading.BoundedSemaphore([value])

  A factory function that returns a new bounded semaphore object. A bounded semaphore checks to make sure its current value doesn’t exceed its initial value. If it does, ValueError is raised. In most situations semaphores are used to guard resources with limited capacity. If the semaphore is released too many times it’s a sign of a bug. If not given, value defaults to 1.

(11)class threading.Thread

  A class that represents a thread of control. This class can be safely subclassed in a limited fashion.See Thread Objects.

(12)class threading.Timer

  A thread that executes a function after a specified interval has passed.See Timer Objects.

(13)threading.settrace(func)

(14)threading.setprofile(func)

(15)threading.stack_size([size])

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/120069.html原文链接:https://javaforall.cn

本文参与?腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021年12月,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体同步曝光计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • threading库对象和方法
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com