add sync queue
This commit is contained in:
parent
92b9f6def4
commit
4c6b27ad43
@ -1,6 +1,6 @@
|
||||
#encoding = utf8
|
||||
|
||||
from .async_task_queue import AsyncTaskQueue
|
||||
from .sync_queue import SyncQueue
|
||||
from .utils import mirror_index, load_model, get_device, load_avatar, config_logging
|
||||
from .audio_utils import melspectrogram, save_wav
|
||||
|
||||
|
32
utils/sync_queue.py
Normal file
32
utils/sync_queue.py
Normal file
@ -0,0 +1,32 @@
|
||||
#encoding = utf8
|
||||
|
||||
import threading
|
||||
from queue import Queue
|
||||
|
||||
|
||||
class SyncQueue:
|
||||
def __init__(self, maxsize):
|
||||
self._queue = Queue(maxsize)
|
||||
self._condition = threading.Condition()
|
||||
|
||||
def put(self, item):
|
||||
with self._condition:
|
||||
while self._queue.full():
|
||||
self._condition.wait()
|
||||
self._queue.put(item)
|
||||
self._condition.notify()
|
||||
|
||||
def get(self):
|
||||
with self._condition:
|
||||
while self._queue.empty():
|
||||
self._condition.wait()
|
||||
item = self._queue.get()
|
||||
self._condition.notify()
|
||||
return item
|
||||
|
||||
def clear(self):
|
||||
with self._condition:
|
||||
while not self._queue.empty():
|
||||
self._queue.get()
|
||||
self._queue.task_done()
|
||||
self._condition.notify_all()
|
Loading…
Reference in New Issue
Block a user