Skip to content

Run BlueskyContext and Worker in subprocess - #343

Merged
joeshannon merged 8 commits into
DiamondLightSource:mainfrom
joeshannon:sp
Feb 5, 2024
Merged

joeshannon merged 8 commits into
DiamondLightSource:mainfrom
joeshannon:sp

Conversation

@joeshannon

Copy link
Copy Markdown
Contributor

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

@joeshannon

Copy link
Copy Markdown
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.

@callumforrester callumforrester left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread src/blueapi/service/main.py Resolved
Comment thread src/blueapi/service/main.py Resolved
@codecov

codecov Bot commented Jan 10, 2024 •

Copy link
Copy Markdown

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.

@joeshannon joeshannon left a comment

Copy link
Copy Markdown
Contributor Author

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.

Comment thread src/blueapi/service/model.py Resolved
Comment thread src/blueapi/service/handler.py Resolved
Comment thread src/blueapi/service/main.py Resolved
@joeshannon
joeshannon force-pushed the sp branch 2 times, most recently from a4873b3 to afdaadd Compare January 17, 2024 16:28
@callumforrester

Copy link
Copy Markdown
Contributor

Would merging this close #317?

@callumforrester

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

No idea :)

@joeshannon
joeshannon force-pushed the sp branch 3 times, most recently from ae32bbd to c4fd452 Compare February 2, 2024 16:15
@joeshannon
joeshannon force-pushed the sp branch 5 times, most recently from ab42bbf to 75925f3 Compare February 5, 2024 13:29
@joeshannon
joeshannon force-pushed the sp branch 2 times, most recently from 8a2fd05 to f94dac4 Compare February 5, 2024 14:42
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.

@callumforrester callumforrester left a comment •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
@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