Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix for the non-quiting beviour of #116.
This adds a ThreadPool and a CancelableQueue.
The CancelableQueue combines a blocking queue with a stop signal. The problem is that the worker threads can only be interrupted when they're blocking on getting work from a queue, or putting results in a queue. This queue then has interruptible
get()
andput()
methods.The ThreadPool class is a better implementation of RaisingThread, where
TheadPool.join()
will behave more like aselect()
on sockets and raise an error as soon as any of the threads encountered an exception.The general idea is that we start all threads as if everything will be allright, putting them in the thread pool. Then we wait for any of them to crash (or all of them to finish without exceptions). If any of them crashes, we call
cancel()
on the queues so that all the other threads also abort their loops. Then, because we're exiting the context of the ThreadPool, we'll wait for them to finish up nicely so that stuff liketry ... finally
still works as expected.It is a contious decision that I don't care about exceptions in any of the other threads once I caught one in one of the threads in the threadpool. You can call
join()
multiple times until it exists without throwing, but in OpusCleaner just one error is already one too many or something.