Skip to content

Commit

Permalink
chore: hide stacktrace from interrupted ConnectedComponents
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhulbert committed Jan 22, 2024
1 parent b754fa7 commit 39c418a
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import net.imglib2.type.volatiles.VolatileUnsignedLongType
import net.imglib2.util.Intervals
import paintera.net.imglib2.view.BundleView
import net.imglib2.view.Views
import org.apache.commons.io.output.NullPrintStream
import org.apache.http.HttpException
import org.apache.http.client.methods.HttpPost
import org.apache.http.entity.ContentType
Expand Down Expand Up @@ -552,16 +553,28 @@ open class SamTool(activeSourceStateProperty: SimpleObjectProperty<SourceState<*
)

val connectedComponents: RandomAccessibleInterval<UnsignedLongType> = ArrayImgs.unsignedLongs(*predictionMask.dimensionsAsLongArray())
/* FIXME: This is annoying, but I don't see a better way around it at the moment.
* `labelAllConnectedComponents` can be interrupted, but doing so causes an
* internal method to `printStackTrace()` on the error. So even when
* It's intentionally and interrupted and handeled, the consol still logs the
* stacktrace to stderr. We temporarily wrap stderr to swalleow it.
* When [https://github.com/imglib/imglib2-algorithm/issues/98] is resolved,
* hopefully this will be as well */
val stdErr = System.err
System.setErr(NullPrintStream())
try {
ConnectedComponents.labelAllConnectedComponents(
filter,
connectedComponents,
StructuringElement.FOUR_CONNECTED
)
} catch (e: InterruptedException) {
System.setErr(stdErr)
LOG.debug("Connected Components Interrupted During SAM", e)
task.cancel()
continue
} finally {
System.setErr(stdErr)
}

val previousPredictionInterval = lastPredictionProperty.get()?.maskInterval?.extendBy(1.0)?.smallestContainingInterval
Expand Down

0 comments on commit 39c418a

Please sign in to comment.