Skip to content
Advertisement

python service inside thread inside singleton

I have a singleton in which I want to receive data from a service. Since I’m new to python the only way I could figure this out was that a service sends the data up to the singleton via a method pointer. I use the thread to hinder the service to lock the singleton with its infinite loop.

The actual circumstances it that I want to extend Mock.GPIO(a mock implementation of RPi.GPIO), https://github.com/codenio/Mock.GPIO, to be able to simulate a button push on a real RPi. The singleton represents a simplified RPi board.

I want to call the socket service with the following echo -n "22:HI" > /dev/tcp/127.0.0.1/5566

I want it to result in

JavaScript

The code acctually runs now.

Instead, I get 5 errors, which is the problem at the moment!!!

JavaScript

I’m lost when it comes to self, class, class(type) and class(object)

PLS point me in the right direction.

Below is the classes I have so far. They are in no way finished.

If you have some other solution to pass a signal change to a callback method registered via the method add_event_detect, I’m open to suggestions.

Reference to the original Mock.GPIO code, https://github.com/codenio/Mock.GPIO/blob/master/Mock/GPIO.py

My Source

JavaScript

My GPIO code

JavaScript

As you can see the “only” difference from the original is that my GPIO instantiates a PiBoard and gets those instants in the methods. In the method add_event_detect I call setChannelEvent in PiBoard.

Advertisement

Answer

The following is a butt ugly solution, but it works. Needs some logic but it has a socket service inside a thread living inside a Singleton. When the service is called an external method, ext_callback, is called, eventually.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement