-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# pylint: disable=C0415,C0413 | ||
__version__ = '0.0.12' | ||
__version__ = '0.0.13' | ||
|
||
|
||
def check_version(): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import time | ||
from threading import Lock | ||
|
||
_lock = Lock() | ||
|
||
|
||
def queued_up(func=None): | ||
"""队列执行函数, 所有被包装的函数共用同一个队列, 该装饰器适用于所有函数""" | ||
if func is None: | ||
return queued_up | ||
|
||
def inner(ctx): | ||
try: | ||
_lock.acquire() | ||
ret = func(ctx) | ||
# 为了易用性,这里的延时大小不开放出来 | ||
# 一般情况下只要不是`同时`发起的请求都是能够成功的 | ||
# 这里设置少量的延时进一步提高成功率 | ||
time.sleep(0.5) | ||
return ret | ||
finally: | ||
_lock.release() | ||
|
||
return inner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters