Removed some optional top-level imports.

Optional top-level imports in Tornado route declarations will trigger
`ImportError`. While this will just mean that those routes will be
skipped, it will also generate a lot of noise on the logs.
This commit is contained in:
Fabio Manganiello 2023-07-01 03:13:38 +02:00
parent e0af2daaff
commit 27cf1bec52
Signed by: blacklight
GPG Key ID: D90FBA7F76362774
4 changed files with 10 additions and 14 deletions

View File

@ -30,8 +30,7 @@ def get_routes():
if hasattr(module, '__routes__'):
routes.extend(module.__routes__)
except Exception as e:
logger.warning('Could not import module %s', mod_name)
logger.exception(e)
logger().warning('Could not import module %s: %s', mod_name, str(e))
continue
return routes

View File

@ -3,8 +3,6 @@ import threading
from dataclasses import asdict, dataclass
from typing import Optional, Union, Tuple, Set
import numpy as np
from platypush.plugins.camera.model.writer import (
StreamWriter,
VideoWriter,
@ -78,6 +76,8 @@ class Camera:
Calculates the effective resolution of the camera in pixels, taking
into account the base resolution, the scale and the rotation.
"""
import numpy as np
assert self.info.resolution, 'No base resolution specified'
rot = (self.info.rotate or 0) * math.pi / 180
sin = math.sin(rot)

View File

@ -7,8 +7,6 @@ import time
from abc import ABC, abstractmethod
from typing import Optional, IO
from PIL.Image import Image
from platypush.utils import get_redis
@ -28,11 +26,12 @@ class VideoWriter(ABC):
self.closed = False
@abstractmethod
def write(self, image: Image):
def write(self, image):
"""
Write an image to the channel.
:param image: PIL Image instance.
:type image: PIL.Image.Image
"""
raise NotImplementedError()
@ -88,7 +87,7 @@ class StreamWriter(VideoWriter, ABC):
self.redis_queue = redis_queue
self.sock = sock
def write(self, image: Image):
def write(self, image):
data = self.encode(image)
with self.ready:
if self.buffer.closed:
@ -116,7 +115,7 @@ class StreamWriter(VideoWriter, ABC):
get_redis().publish(self.redis_queue, data)
@abstractmethod
def encode(self, image: Image) -> bytes:
def encode(self, image) -> bytes:
"""
Encode an image before sending it to the channel.

View File

@ -5,8 +5,6 @@ import time
from abc import ABC
from typing import Optional, Tuple
from PIL.Image import Image
from platypush.plugins.camera.model.camera import Camera
from platypush.plugins.camera.model.writer import (
VideoWriter,
@ -73,7 +71,7 @@ class FFmpegWriter(VideoWriter, ABC):
def is_closed(self):
return self.closed or not self.ffmpeg or self.ffmpeg.poll() is not None
def write(self, image: Image):
def write(self, image):
if self.is_closed():
return
@ -146,7 +144,7 @@ class FFmpegStreamWriter(StreamWriter, FFmpegWriter, ABC):
self._reader = threading.Thread(target=self._reader_thread)
self._reader.start()
def encode(self, image: Image) -> bytes:
def encode(self, image) -> bytes:
return image.convert('RGB').tobytes()
def _reader_thread(self):
@ -173,7 +171,7 @@ class FFmpegStreamWriter(StreamWriter, FFmpegWriter, ABC):
self._sock_send(self.frame)
def write(self, image: Image):
def write(self, image):
if self.is_closed():
return