Skip to content

Conversation

@ptsOSL
Copy link
Collaborator

@ptsOSL ptsOSL commented May 6, 2025

No description provided.

ptsOSL added 3 commits May 6, 2025 09:59
Compromise between giving enough time to get this potentially usefull optional pv and not slowing startup too much if it isnt available
Previously, if the pyAT simulation raised an exception we wouldnt update self._lattice_date but would still run the pv update callbacks on the old data. Now we skip this
@ptsOSL ptsOSL requested review from MJGaughran and T-Nicholls May 6, 2025 14:14
@codecov
Copy link

codecov bot commented May 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.87%. Comparing base (8942c3a) to head (fc6f4f8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #45      +/-   ##
==========================================
+ Coverage   93.84%   93.87%   +0.03%     
==========================================
  Files           6        6              
  Lines         390      392       +2     
==========================================
+ Hits          366      368       +2     
  Misses         24       24              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

)
except Exception as e:
warn(at.AtWarning(e), stacklevel=1)
logging.warning(
Copy link
Contributor

Choose a reason for hiding this comment

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

This also skips the cothread.Yield(). Is that appropriate?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, if you imagine there are no further caputs or similar, doesn't this mean the Signal never gets sent and any pytac gets or wait_for_calculations timeout?

Copy link
Contributor

@MJGaughran MJGaughran May 6, 2025

Choose a reason for hiding this comment

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

It would be helpful to know the motivation for this change, as this feels like this code would all be changed after the threading rework later on, anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The motivation is:

  1. Don't post changes to PVs when the simulation hasnt been updated because
    - Clients may think that their caput has caused the pvs to update but not change value, so the feedbacks for example may conclude it needs to increase its delta.
    - It wastes time updating thousands of pvs
  2. Improve logging, the warn() is only printed once in its current implementation, so if we keep getting this exception, after the first warning, the user will assume everything is running fine and they will see pvs updating, but they arent updating based on the users setpoints.

So I think it is quite an important change.

Skipping cothread.Yield() may cause an issue, its hard for me to know. We do potentially yield immediately after when we call _gather_one_sample() which waits on an item to be in _queue. Im not sure if cothread will always yield here or only yield if the queue is empty, asyncio would always yield.

Also it would make sense for the wait_for_calculations to timeout as the calculation has failed. We have recieved a caput, so we mark _up_to_date false, then we fail to implement the caput, so _up_to_date should remain false unless a later caput causes the simulation to succeed, in which case we will yield.

So I think its okay, this will all change when we switch to asyncio of course.

Copy link
Collaborator

@T-Nicholls T-Nicholls left a comment

Choose a reason for hiding this comment

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

As discussed:

  • This is better than the current behaviour, but doesn't fully solve the potential issues with exceptions in this method.
  • Using a try/except/else rather than continue would avoid skipping the yield statement.
  • It is a vanishingly infrequent edge-case where this could actually cause problems during normal operation.
  • It will all likely be changed by the asyncio move and future threading changes anyway.

For these reasons, I don't really mind this being merged as is if you want these changes urgently; otherwise, we can wait until after the asyncio move and address this fully.

@ptsOSL
Copy link
Collaborator Author

ptsOSL commented May 7, 2025

The main reason I wanted to merge was that the pytests were failing due to not closing the csv files, so I am happy to merge it.

@ptsOSL ptsOSL merged commit d0317c0 into main May 7, 2025
22 checks passed
@ptsOSL ptsOSL deleted the minor-improvements branch June 27, 2025 12:35
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.

4 participants