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

HTTPCameraAgent write file change #740

Merged
merged 3 commits into from
Aug 29, 2024
Merged

HTTPCameraAgent write file change #740

merged 3 commits into from
Aug 29, 2024

Conversation

davidvng
Copy link
Contributor

Description

  • Move the write to file into a try-except block and write in chunks
  • Slight change to setting connected for each camera

Motivation and Context

To avoid ReadTimeoutError during writing to file, since the response data is streamed

How Has This Been Tested?

Tested on daq-dev

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@davidvng davidvng requested a review from BrianJKoopman August 29, 2024 15:10
Copy link
Member

@BrianJKoopman BrianJKoopman left a comment

Choose a reason for hiding this comment

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

Looks good, though we should be more specific in the error handling.

out_file.flush()
os.fsync(out_file.fileno())
self.log.debug(f"Wrote {ctime}.jpg to /{camera['location']}/{ctime_dir}.")
except BaseException as e:
Copy link
Member

Choose a reason for hiding this comment

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

Catching BaseException like this isn't ideal. That catches exceptions that indicate the program should exit like SystemExit and KeyboardInterrupt, which if raised at the right time could make the agent difficult to stop.

With this code block:

shutil.copyfileobj(response.raw, out_file)
# Ensure all data is written to the disk before copying to latest
out_file.flush()
os.fsync(out_file.fileno())

We know the error we were running into is another urllib3.exceptions.ReadTimeoutError on the shutil.copyfileobj line. I don't know that you're going to see that with the new chunk iteration code.

Good practice is to catch and handle specific errors, so my preference here is to except ReadTimeoutError as e, like you do above, with the log indicating a timeout occurred. If needed, catching Exception is better than the broader BaseException, as that doesn't catch those exit exceptions.

@BrianJKoopman BrianJKoopman merged commit 558bb17 into main Aug 29, 2024
5 checks passed
@BrianJKoopman BrianJKoopman deleted the http-camera-fix branch August 29, 2024 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants