Skip to content

Commit

Permalink
Merge pull request #88 from Idein/feature/retry-open-device
Browse files Browse the repository at this point in the history
  • Loading branch information
riku179 authored Jul 13, 2023
2 parents f722d94 + de2363b commit 9a6be8c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion actfw_core/v4l2/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import mmap
import os
import select
import time
import warnings
from ctypes import *
from ctypes.util import find_library
from typing import List
Expand Down Expand Up @@ -830,7 +832,21 @@ def __init__(self, device="/dev/video0", blocking=False):
flags = os.O_RDWR
if not blocking:
flags |= os.O_NONBLOCK
self.device_fd = os.open(self.device, flags)

for i in range(3):
try:
self.device_fd = os.open(self.device, flags)
break
except OSError as e:
# retry 3 times when device is busy
if e.errno != errno.EBUSY or i == 2:
raise RuntimeError(f"open {self.device}: {errno.errorcode[e.errno]}")
warnings.warn(
f"Retrying to open {self.device} after 1 second.",
RuntimeWarning,
)
time.sleep(1)

self.converter = _v4lconvert.create(self.device_fd)
self.buffers: Optional[List[VideoBuffer]] = None # set when enqueu

Expand Down

0 comments on commit 9a6be8c

Please sign in to comment.