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

Allow re-scan of devices to support hot-plugging #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

j3kestrel
Copy link

The use of a bare generator in EVENT_MAP['type_codes'] makes EVENT_MAP a single use object. Converting the generator to a tuple allows reuse of EVENT_MAP and constructing a new DeviceManager that re-scans for devices.

Addresses issue #66

The use of a bare generator in `EVENT_MAP['type_codes']` makes `EVENT_MAP` a single use object.  Converting the generator to a tuple allows reuse of `EVENT_MAP` and constructing a new `DeviceManager` that re-scans for devices.
@j3kestrel
Copy link
Author

I now see that pull request #81 fixes the same problem, but doesn't add a function to re-scan devices.

@zeth
Copy link
Owner

zeth commented Jun 21, 2021

Thanks. I just need to find a day to test with the 100 devices.

@BirdLogics
Copy link

This should also fix #106. Attempting to create a new DeviceManager instance manually does not work as rescan because of the bare generator in EVENT_MAP.

@cathartyc
Copy link

cathartyc commented Feb 17, 2024

This fix works only when inputs is imported as a whole. It would not change the instance of devices when it is imported individually (from inputs import devices), as it is shown instead in the examples.

>>> import inputs
>>> from inputs import devices
>>> 
>>> inputs.devices == devices
True
>>> inputs.rescan_devices()
>>> 
>>> inputs.devices == devices
False
>>>

@j3kestrel
Copy link
Author

I suspect that is because input.devices not mutated, it is replaced. As a result, inputs.devices and local devices no longer reference the same object. Any local references to input.devices would need to be refreshed after using rescan_devices().

import inputs`
devices = inputs.devices
[...]
inputs.rescan_devices()
devices = inputs.devices

Or, perhaps rescan_devices() could return devices so that it becomes devices = inputs.rescan_devices(). The problem with all of this is that it doesn't solve the problem of a developer expecting devices to be mutated instead of replaced and not expecting to need to re-cache the local reference.

Is there a better solution other than updating examples and documentation?

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