Menu ▾ ▴

#2909 Jython runInParallel should support monitored functions

nextrelease
open
nobody
None
5
2026-10-23
2026-10-23
No

I think it would be fairly easy to monitor all of the jobs to be run in parallel, where each job's progress is monitored. George has fftPower(bx) + fftPower(by) + fftPower(bz) where the three can be done at the same time, but the current runInParallel doesn't monitor each of the jobs, just looks at whether each is done or not. Since the number of jobs (3) is less than the number of threads (~6), no progress is reported.

I started coding this and realized I didn't have time to complete and verify it. Here's the code:

        for ( int i=0; i<argument.size(); i++ ) {
            final int I= i;
            result.add( I, null );
            exceptions.add( I,null );
            callables.add( I, new Callable<Object>() {
                @Override
                public Object call() throws Exception {
                    try {
                        String[] kw= new String[] { "monitor" };
                        ProgressMonitor m= new NullProgressMonitor();
                        PyObject[] args= new PyObject[] { Py.java2py(argument.get(I)), Py.java2py(m) };
                        Object result1;
                        try {
                            result1= job.__call__( args, kw );
                        } catch ( PyException ex ) {
                            // fall back to old call
                            result1= job.__call__( Py.java2py(argument.get(I)) );
                        }
                        result.set( I, result1 );
                        return result1;
                    } catch ( Exception e ) {
                        exceptions.set( I, e );
                        return null;
                    }
                }
            } );
        }

The plan was to try job(arg,monitor=m) and when that fails fall back to the old 1-arg API.

Discussion