Skip to content

SenseHat object cannot be instantiated more than once. #148

Open
@nralbers

Description

@nralbers

If more than a single SenseHat object is instantiated on a machine any calls to sensor data will return 0 instead of the actual sensor value.

Simple test:

from sense_hat import SenseHat
import unittest


class TestSingleton(unittest.TestCase):
    def test_singleton(self):
        sense1 = SenseHat()
        sense2 = SenseHat()
        self.assertEqual(sense1.temperature, sense2.temperature)    

if __name__ == "__main__":
    unittest.main()

This will fail on the current codebase.
I've added pull request #147 to at least prevent this occuring in a single python program by converting the SenseHat object to a thread-safe Singleton, but this will not prevent the issue arriving if multiple projects are using the SenseHat object on the same machine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions