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

set atexit in mockupcamera #1169

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
11 changes: 9 additions & 2 deletions mxcubecore/HardwareObjects/TangoLimaMpegVideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
</object>
"""

import atexit
import logging
import os
import signal
import subprocess
import uuid
from typing import (
Expand Down Expand Up @@ -71,6 +75,10 @@ def get_available_stream_sizes(self) -> List[Tuple[int, int]]:

return video_sizes

def clean_up(self) -> None:
logging.getLogger("HWR").info("Shutting down video_stream...")
os.kill(self._video_stream_process.pid, signal.SIGTERM)

def start_video_stream_process(self) -> None:
if (
not self._video_stream_process
Expand All @@ -97,8 +105,7 @@ def start_video_stream_process(self) -> None:
close_fds=True,
)

with open("/tmp/mxcube.pid", "a") as f:
f.write("%s " % self._video_stream_process.pid)
atexit.register(self.clean_up)
Comment on lines -100 to +108
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I now also modified the registration for the video-streamer in tangoLimaMPEGVideo


def stop_streaming(self) -> None:
if self._video_stream_process:
Expand Down
9 changes: 9 additions & 0 deletions mxcubecore/HardwareObjects/mockup/MDCameraMockup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Class for cameras connected to framegrabbers run by Taco Device Servers"""

import atexit
import logging
import os
import signal
import subprocess
import time
from typing import (
Expand Down Expand Up @@ -115,6 +118,10 @@ def get_stream_size(self) -> Tuple[int, int, float]:
scale = float(width) / self.get_width()
return (width, height, scale)

def clean_up(self):
logging.getLogger("HWR").info("Shutting down video_stream...")
os.kill(self._video_stream_process.pid, signal.SIGTERM)

def start_video_stream_process(self) -> None:
if (
not self._video_stream_process
Expand All @@ -141,6 +148,8 @@ def start_video_stream_process(self) -> None:
close_fds=True,
)

atexit.register(self.clean_up)

def stop_streaming(self) -> None:
if self._video_stream_process:
try:
Expand Down
Loading