Conversation
|
Hm, very promising. :) Maybe #235 can help you with the states. |
There was a problem hiding this comment.
I wouldn't worry about interface specific behaviour, since that is to be expected on all operations.
can/bus.py
Outdated
|
|
||
| def __exit__(self, exc_type, exc_val, exc_tb): | ||
| for t in self._tx_threads: | ||
| t.stop() |
There was a problem hiding this comment.
Good idea. It could even be moved to the .shutdown() method in my opinion.
| notifier.stop() | ||
|
|
||
|
|
||
| class Back2BackTestCaseWithContext(unittest.TestCase): |
There was a problem hiding this comment.
Don't think this is needed. The other test should suffice.
|
@edobez Any updates on this? |
|
Uhm, I guess this method should not assume that that attribute exists. It is not documented anywhere! And shouldn't it call |
|
I removed the |
|
I will merge it and then combine |
Hello everybody,
I am a new user of
python-canbut I decided to contribute a little to it.I have started to work on a new feature: the context manager implementation for the Bus class, and I would like to do the same with other classes that require accessing and releasing resources, like Notifier.
In this way it's possible to open and close a bus instance automatically, i.e.:
The context manager implementation is quite straight forward. What I wonder about is how to implement the exception behaviour.
In order to get an exception when requesting an operation after the bus has been closed, the instance should know about its 'openness' (note that this applies also without the context manager).
At the moment if you try to call a function after the
shutdown()call, you'll get an exception specific to one interface implementation.Relying on this, in my opinion, it's not the best since different interfaces (thus different implementations) can behave in different ways._
For example, the virtual interface doesn't release any resource after its shutdown and continues to work even after the closing call.
My idea is to use a state variable inside the instance that indicates if the bus is open or not, and use this information before trying to do any operation on the bus.
This would require to edit all the current interface implementations by adding some helper functions, something like what I did on the
virtualclass and that you can see in the PR.Let me know if this can be a good idea.