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

Run BlueskyContext and Worker in subprocess #343

Merged
merged 8 commits into from
Feb 5, 2024

Conversation

joeshannon
Copy link
Contributor

This approach is possibly not the best design as it results in four definitions of all the functions.

@joeshannon
Copy link
Contributor Author

These changes do allow the run engine and worker to run in a subprocess but I'm not sure this is the best design as it ends up with many implementations of these methods.

I've tested it though and it does work.

Probably something to discuss next week.

Copy link
Contributor

@callumforrester callumforrester 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, needs tests. See comment about intermittent issue.

I think after this we can clean up subprocess_handler.py a bit more and break up handler as discusses

src/blueapi/service/main.py Outdated Show resolved Hide resolved
src/blueapi/service/main.py Outdated Show resolved Hide resolved
src/blueapi/service/subprocess_handler.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (f0c1d5e) 87.17% compared to head (5a70803) 88.70%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #343      +/-   ##
==========================================
+ Coverage   87.17%   88.70%   +1.53%     
==========================================
  Files          42       43       +1     
  Lines        1645     1797     +152     
==========================================
+ Hits         1434     1594     +160     
+ Misses        211      203       -8     

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

Copy link
Contributor Author

@joeshannon joeshannon left a comment

Choose a reason for hiding this comment

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

Probably needs some tests of the subprocess handler.

src/blueapi/service/subprocess_handler.py Show resolved Hide resolved
src/blueapi/service/model.py Show resolved Hide resolved
src/blueapi/service/handler.py Outdated Show resolved Hide resolved
src/blueapi/service/main.py Outdated Show resolved Hide resolved
@callumforrester
Copy link
Contributor

Would merging this close #317?

@callumforrester
Copy link
Contributor

I think the four definitions of functions flaw can be solved by a refactor in the future, this is a good first attempt.

@joeshannon
Copy link
Contributor Author

Would merging this close #317?

Yes, is you commenting of that sufficient to auto close the issue when this is merged?

@callumforrester
Copy link
Contributor

No idea :)

Setting environment state to not valid will cause the subprocess context
to be reloaded.
Dependency override should import from main.py (app) not handler module.
Added mostly to satisfy type checking as the _subprocess field is
set to None before it is started and when it is stopped.
Copy link
Contributor

@callumforrester callumforrester left a comment

Choose a reason for hiding this comment

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

Please could you make issues to do the following (unless you feel like doing them now but I think we should get this merged):

  • Document this approach, probably requires an explanation page and perhaps an ADR
  • Add CLI commands to inspect/restart the environment
  • Better error handling if someone calls, say, /devices while the environment is restarting

@joeshannon
Copy link
Contributor Author

Please could you make issues to do the following (unless you feel like doing them now but I think we should get this merged)

Yes I agree - it's probably best to draw a line under this and make new issues.

@joeshannon joeshannon merged commit c09b5c6 into DiamondLightSource:main Feb 5, 2024
15 checks passed
@joeshannon joeshannon deleted the sp branch February 5, 2024 18:17
callumforrester added a commit that referenced this pull request Feb 7, 2024
Closes #369

The validated and processed parameters from a plan request were being
cached inside the `Task` class because they were needed in two separate
threads. Unfortunately, with the introduction of the subprocess (#343),
pickling was causing issues with the cached object (see #369 for more
details).

This PR is the simplest solution: remove the cache and generate the
parameters twice. It also adds regression tests for the bug case in #369
ZohebShaikh pushed a commit that referenced this pull request May 7, 2024
Create SubprocessHandler as additional BlueskyHandler implementation to
forward calls to a subprocess. This is to allow a new REST endpoint with
the result of reloading the plans and devices without having to restart
the service.

Additionally the API version is incremented due to new schema and a
reference to delete_task replaced with clear_pending_task which was
missed in a previous PR.

Further improvements required in later PRs.
ZohebShaikh pushed a commit that referenced this pull request May 7, 2024
Closes #369

The validated and processed parameters from a plan request were being
cached inside the `Task` class because they were needed in two separate
threads. Unfortunately, with the introduction of the subprocess (#343),
pickling was causing issues with the cached object (see #369 for more
details).

This PR is the simplest solution: remove the cache and generate the
parameters twice. It also adds regression tests for the bug case in #369
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