Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove logger setup #73

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ name = "acquire"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.18", features = [
pyo3 = { version = "0.19", features = [
"extension-module",
"anyhow",
"abi3-py38",
"serde",
] }
pyo3-log = "0.8"
numpy = "0.18"
numpy = "0.19"
log = "0.4"
anyhow = "1.0"
parking_lot = "0.12"
serde = { version = "1.0", features = ["derive"] }
pythonize = "0.18"
pythonize = "0.19"

[build-dependencies]
bindgen = "0.65"
bindgen = "0.66"
cmake = "0.1"
http = "0.2"
json = "0.12"
Expand Down
30 changes: 19 additions & 11 deletions python/acquire/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import time
from typing import TYPE_CHECKING, Any, Generator, List, Literal, Optional, Tuple, Union
from typing import (
TYPE_CHECKING,
Any,
Generator,
List,
Literal,
Optional,
Tuple,
Union,
)

import numpy.typing as npt

Expand All @@ -14,13 +23,6 @@
import napari # type: ignore


FORMAT: str = (
"%(levelname)s %(name)s %(asctime)-15s %(filename)s:%(lineno)d %(message)s"
)
logging.basicConfig(format=FORMAT)
logging.getLogger().setLevel(logging.INFO)


g_runtime: Optional[Runtime] = None
"""The global acquire runtime."""

Expand Down Expand Up @@ -159,7 +161,9 @@ def update_layer(args: Tuple[npt.NDArray[Any], int]) -> None:
viewer.add_image(new_image, name=layer_key)

@thread_worker(connect={"yielded": update_layer})
def do_acquisition() -> Generator[Tuple[npt.NDArray[Any], int], None, None]:
def do_acquisition() -> (
Generator[Tuple[npt.NDArray[Any], int], None, None]
):
logging.basicConfig(level=logging.DEBUG)
logging.getLogger().setLevel(logging.DEBUG)

Expand Down Expand Up @@ -188,9 +192,13 @@ def next_frame() -> Optional[npt.NDArray[Any]]:
if packet := runtime.get_available_data(stream_id):
n = packet.get_frame_count()
nframes[stream_id] += n
logging.info(f"[stream {stream_id}] frame count: {nframes}")
logging.info(
f"[stream {stream_id}] frame count: {nframes}"
)
f = next(packet.frames())
logging.debug(f"stream {stream_id} frame {f.metadata().frame_id}")
logging.debug(
f"stream {stream_id} frame {f.metadata().frame_id}"
Copy link
Contributor

@andy-sweet andy-sweet Aug 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I avoid f-strings for logging (and in particular debug logs) because the f-string is evaluated even if the log is not. Instead I use the varargs/printf style that is baked into logging.

Suggested change
f"stream {stream_id} frame {f.metadata().frame_id}"
"stream %d frame %d", stream_id, f.metadata().frame_id

Not specific to this PR, but likely want to make this change some time. Also, this would be needed in multiple places - not just here.

)
return f.data().squeeze().copy()
return None

Expand Down
2 changes: 1 addition & 1 deletion src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl RawAvailableData {
let mut cur = self.beg.as_ptr();
let end = self.end.as_ptr();
while cur < end {
let frame: &capi::VideoFrame = &*cur;
let frame: &capi::VideoFrame = &std::ptr::read_unaligned(cur);
log::trace!(
"[stream {}] Advancing count for frame {} w size {}",
self.stream_id,
Expand Down