fix(hil-serl): drain queue on get_last_item_from_queue (#1524)
* fix(hil-serl): drain queue on get_last_item_from_queue * parametrize queue tests * revert changes for Darwin * revert parametrize queue tests * add test_get_last_item_multiple_items_with_torch_queue * update test_get_last_item_multiple_items_with_torch_queue * update test_get_last_item_multiple_items_with_torch_queue
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import platform
|
||||
from contextlib import suppress
|
||||
from queue import Empty
|
||||
from typing import Any
|
||||
|
||||
@@ -30,10 +32,21 @@ def get_last_item_from_queue(queue: Queue, block=True, timeout: float = 0.1) ->
|
||||
item = None
|
||||
|
||||
# Drain queue and keep only the most recent parameters
|
||||
try:
|
||||
while True:
|
||||
if platform.system() == "Darwin":
|
||||
# On Mac, avoid using `qsize` due to unreliable implementation.
|
||||
# There is a comment on `qsize` code in the Python source:
|
||||
# Raises NotImplementedError on Mac OSX because of broken sem_getvalue()
|
||||
try:
|
||||
while True:
|
||||
item = queue.get_nowait()
|
||||
except Empty:
|
||||
pass
|
||||
|
||||
return item
|
||||
|
||||
# Details about using qsize in https://github.com/huggingface/lerobot/issues/1523
|
||||
while queue.qsize() > 0:
|
||||
with suppress(Empty):
|
||||
item = queue.get_nowait()
|
||||
except Empty:
|
||||
pass
|
||||
|
||||
return item
|
||||
|
||||
Reference in New Issue
Block a user