LogikSim / LogikSimPython

Python prototype of a digital logic simulator
http://www.logiksim.org/
GNU General Public License v3.0
2 stars 1 forks source link

QueueFeederThread not Joined when Controller Exists #53

Open christianbrugger opened 9 years ago

christianbrugger commented 9 years ago

Currently in many tests there are unjoined threads, after running the tests. Many of them are QueueFeederThread that are part of the multiprocessing.Queue implementation. I suggest we close them somewhere with:

self.scene._controller._channel_in.close()
self.scene._controller._channel_in.join_thread()
self.scene._controller._channel_out.close()
self.scene._controller._channel_out.join_thread()

@hacst what would be the best place to close these threads?

Currently more than 30 unittests fail because of this issue. To enables detection of unjoined thread remove the line: https://github.com/LogikSim/LogikSim/blob/master/src/tests/helpers.py#L164

hacst commented 9 years ago

We'll need to add explicit shutdown functions to all our classes that create such objects and make sure to call them throughout the hierarchy. Kind of a pita but without RAII there's not much you can do to work around this. We'll probably want to move the creation of these queues out of the controller somewhere that already deals with application lifetime. We'll need that later anyways so we can actually use multiple processes. It'll probably end up - in wrapped form - where we currently setup the backend/shutdown stuff.

Beyond precisely controlling the life-time what we can also investigate is why exactly they aren't joined on shutdown. I'd assume python guarantees us to call __del__ on them during shutdown so the issue is probably that they don't force a join there. If that is the case adding that on the queue itself might be enough to resolve the issue.