阻塞器, 单人阻塞器和多人阻塞器
单人阻塞器:
一个线程调用lock()会立即阻塞, 直到另一个线程调用unlock()为止, 同一个阻塞器只能阻塞一个线程
测试代码:
if __name__ == '__main__':
print('测试单人阻塞器')
def fun():
for i in range(5):
time.sleep(1)
a.unlock()
import threading
import time
a = BLock()
threading.Thread(target=fun).start()
for i in range(5):
print('开始锁定', i, time.strftime('%H:%M:%S', time.localtime()))
a.lock() # 阻塞
print(' 解除', i, time.strftime('%H:%M:%S', time.localtime()))
print('结束\n\n')
多人阻塞器:
任何线程在调用lock()的时候都会被阻塞, 直到有一个线程调用一次unlock()来解除所有阻塞
测试代码
if __name__ == '__main__':
print('测试多人阻塞器')
def fun1(value):
print('阻塞', value)
a.lock()
print(' 解除', value)
def fun2():
print('--2秒后解除所有阻塞--', time.strftime('%H:%M:%S', time.localtime()))
time.sleep(2)
print('--即将解除所有阻塞--', time.strftime('%H:%M:%S', time.localtime()))
a.unlock()
import threading
import time
a = BLock_more()
for i in range(5):
threading.Thread(target=fun1, args=(i,)).start()
threading.Thread(target=fun2).start()
a.join()
print('结束')
单人阻塞器:
一个线程调用lock()会立即阻塞, 直到另一个线程调用unlock()为止, 同一个阻塞器只能阻塞一个线程
测试代码:
if __name__ == '__main__':
print('测试单人阻塞器')
def fun():
for i in range(5):
time.sleep(1)
a.unlock()
import threading
import time
a = BLock()
threading.Thread(target=fun).start()
for i in range(5):
print('开始锁定', i, time.strftime('%H:%M:%S', time.localtime()))
a.lock() # 阻塞
print(' 解除', i, time.strftime('%H:%M:%S', time.localtime()))
print('结束\n\n')
多人阻塞器:
任何线程在调用lock()的时候都会被阻塞, 直到有一个线程调用一次unlock()来解除所有阻塞
测试代码
if __name__ == '__main__':
print('测试多人阻塞器')
def fun1(value):
print('阻塞', value)
a.lock()
print(' 解除', value)
def fun2():
print('--2秒后解除所有阻塞--', time.strftime('%H:%M:%S', time.localtime()))
time.sleep(2)
print('--即将解除所有阻塞--', time.strftime('%H:%M:%S', time.localtime()))
a.unlock()
import threading
import time
a = BLock_more()
for i in range(5):
threading.Thread(target=fun1, args=(i,)).start()
threading.Thread(target=fun2).start()
a.join()
print('结束')
Metadata
Release files for zblocker 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| zblocker-1.0.2.tar.gz | 2.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| zblocker-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 5.4 kB
Release files / zblocker-1.0.2.tar.gz
| Download URL | zblocker-1.0.2.tar.gz |
|---|---|
| Size | 2.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
238d3b64d826d749dffdc10e79b840fa62a7bbc3bd3713e0da7e61ec1e013e02
|
|
BLAKE2b-256 checksum How to use checksums |
43dae828a62ef1c4125763365df843a853282dff5770c677696e4e7c356149f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5
|
Release files / zblocker-1.0.2-py3-none-any.whl
| Download URL | zblocker-1.0.2-py3-none-any.whl |
|---|---|
| Size | 2.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ceebb44ab793205f97482521fb45163e0de8dc08af772ddbedecc916f0b1b69e
|
|
BLAKE2b-256 checksum How to use checksums |
3d620097c96e1341b7f40528b75d6282d824433e31bfe300bad5288e765822e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5
|
Security for zblocker 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.