python docs库_python库之_thread

_thread库方法

(1) _thread.error

(2)_thread.LockTyoe

(3)_thread.start_new_thread

(4)_thread.interrupt_main

Raise a KeyboardInterrupt exception in the main thread. A subthread can use this function to interrupt the main thread.

(5)_thread.exit

(6)_thread.allocate_lock

import _thread

a_lock=_thread.allocate_lock()

with a_lock:

print("a_lock is locked while this executes")

(7)_thread.get_ident

(8)_thread.stack_size

(9)_thread.TIMEOUT_MAX

(10)lock.acquire(waitflag=1,timeout=-1)

Without any optional argument, this method acquires the lock unconditionally, if necessary waiting until it is released by another thread (only one thread at a time can acquire a lock — that’s their reason for existence).

If the integer waitflag argument is present, the action depends on its value: if it is zero, the lock is only acquired if it can be acquired immediately without waiting, while if it is nonzero, the lock is acquired unconditionally as above.

If the floating-point timeout argument is present and positive, it specifies the maximum wait time in seconds before returning. A negative timeout argument specifies an unbounded wait. You cannot specify a timeout if waitflag is zero.

The return value is True if the lock is acquired successfully, False if not.

(11)lock.release()

(12)lock.locked()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值