-
Notifications
You must be signed in to change notification settings - Fork 179
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
feat(api): register module instances on os events #4441
Conversation
Previously, the hardware controller only became aware of underlying connected hardware modules when it was told to look via an http endpoint (only effectively used by the run app). In order to remove this unnecessary reliance, the hardware controller now watches the filesystem for changes using aionotify (a thin python wrapper of linux util). Changes to the physically connected modules should now be instantly reflected in the hardware controllers attached modules regardless of whether the hardware controller is observed by a third party or not. No more Schrödinger's modules re #3580
b3b55b3
to
95d3559
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inline comments. Also,
- We need to specify the new
aionotify
dependency in our pipfile specs (for devs) and in ourinstall_requires
in setup.py for pypi, presumably gated around linux - Bit concerned about the flow around updating modules when they switch ports, but I haven't tested yet
- We also need to test just what happens when you create a hardware controller on windows, since manufacturing does this all the time (or will): it should run, although it's ok if it's degraded
Codecov Report
@@ Coverage Diff @@
## edge #4441 +/- ##
==========================================
+ Coverage 55.47% 56.62% +1.14%
==========================================
Files 904 906 +2
Lines 26119 28415 +2296
==========================================
+ Hits 14490 16089 +1599
- Misses 11629 12326 +697
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple more inline changes
path='/dev', | ||
flags=(aionotify.Flags.CREATE | aionotify.Flags.DELETE)) | ||
except AttributeError: | ||
MODULE_LOG.info( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should definitely be warning
level
MODULE_LOG.info(f'Module Removed: {maybe_module_at_port}') | ||
if maybe_module_at_port is not None and \ | ||
aionotify.Flags.CREATE in flags: | ||
await register_modules(new_modules=[maybe_module_at_port]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we coalesce these? could this happen with
- events for more than one module
- create and then delete event for a module
- delete and then create event for a module
@@ -201,3 +228,6 @@ def probe(self, axis: str, distance: float) -> Dict[str, float]: | |||
self.pause() | |||
await asyncio.sleep(duration_s) | |||
self.resume() | |||
|
|||
def __exit__(self, exc_type, exc_value, traceback): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this wants to be __del__
(https://docs.python.org/3/reference/datamodel.html#object.__del__), __exit__
(https://docs.python.org/3/reference/datamodel.html#object.__exit__) is for context managers, aka things you use in a with
statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more little issue
2a5633c
to
1718908
Compare
@@ -201,3 +234,6 @@ def probe(self, axis: str, distance: float) -> Dict[str, float]: | |||
self.pause() | |||
await asyncio.sleep(duration_s) | |||
self.resume() | |||
|
|||
def __del__(self, exc_type, exc_value, traceback): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at the docs again (https://docs.python.org/3/reference/datamodel.html#object.__del__), this can't take any arguments unfortunately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
overview
Previously, the hardware controller only became aware of underlying connected hardware modules when
it was told to look via an http endpoint (only effectively used by the run app). In order to remove
this unnecessary reliance, the hardware controller now watches the filesystem for changes using
aionotify (a thin python wrapper of linux util). Changes to the physically connected modules should
now be instantly reflected in the hardware controllers attached modules regardless of whether the
hardware controller is observed by a third party or not. No more Schrödinger's modules
re #3580
changelog
hardware_controller.API.attached_modules
as a list ofAbstractModule
instancesbuild_hardware_controller
are now skipped in caseaionotify
/inotify
is not present (non-linux environments)review requests