Skip to content

Commit b8c9335

Browse files
author
Stefan Hahmann
committed
Add a retry mechanism when Python runtime exceptions occur and use it within RegionPropsComputation
Introduce `runScriptWithRetries()` method to handle `PythonRuntimeException` with a retry logic, improving the robustness of the computation workflow.
1 parent 4f7d519 commit b8c9335

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/main/java/org/mastodon/mamut/linking/trackastra/appose/computation/RegionPropsComputation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private SingleTimepointRegionProps computeSingleTimepointProps( final Source< ?
131131
inputs.put( IMAGE, imageNDArray );
132132
inputs.put( MASK, masksNDArray );
133133

134-
Service.Task result = runScript();
134+
Service.Task result = runScriptWithRetries( 1, 10 );
135135
ShmImg< IntType > labels = new ShmImg<>( ( NDArray ) result.outputs.get( LABELS ) );
136136
ShmImg< IntType > timepoints = new ShmImg<>( ( NDArray ) result.outputs.get( TIMEPOINTS ) );
137137
LoopBuilder.setImages( timepoints ).multiThreaded().forEachPixel( p -> p.set( timepoint ) ); // all timepoints are the same

src/main/java/org/mastodon/mamut/util/appose/ApposeProcess.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,27 @@ protected Service.Task runScript() throws IOException
185185
return currentTask;
186186
}
187187

188+
protected Service.Task runScriptWithRetries( final int attempt, final int maxRetries ) throws IOException
189+
{
190+
try
191+
{
192+
return runScript();
193+
}
194+
catch ( PythonRuntimeException e )
195+
{
196+
if ( attempt <= maxRetries )
197+
{
198+
logger.warn( "Python runtime exception on attempt {}/{}. Retrying...", attempt, maxRetries );
199+
return runScriptWithRetries( attempt + 1, maxRetries );
200+
}
201+
else
202+
{
203+
logger.error( "Python runtime exception on final attempt {}/{}. No more retries.", attempt, maxRetries );
204+
throw e;
205+
}
206+
}
207+
}
208+
188209
public void cancel()
189210
{
190211
pythonWorker.kill();

0 commit comments

Comments
 (0)