orthonym.batch_pool#

Note

Internal API. Names and behaviour may change between releases.

Name a list of inputs in worker processes and hand the results back in input order.

run_ordered is the parallel path of orthonym --batch --jobs N and of scripts/speed_bench.py. Each worker is a fresh spawn process: init_fn runs once in it (build the namer, limit the BLAS threads), then row_fn runs once per input; a worker ends itself when its parent is gone (_worker_start). The parent keeps at most jobs inputs in flight, one per worker, sends the next as one comes back, and yields the results in index order, so the output of N workers is the output of one, line for line.

A worker that dies in the middle of a row (a crash of the JVM or of RDKit, os._exit) breaks the whole pool: concurrent.futures then fails every unfinished future with BrokenProcessPool, the rows that only shared the pool included. The rows in flight at the break (at most jobs) are sent again, each in a pool of its own, so a second break can only be the row’s own; that index yields error_row(item). The rows not yet sent go on in a new pool. (multiprocessing.Pool.imap is not used: it never reports a worker killed mid-task and blocks for ever.)

The JVM budget (orthonym.jvm_budget) is the caller’s: a caller that reserves slots reserves the N once, and the workers reserve none (a worker that asks for a slot of a full budget waits until its timeout).

orthonym.batch_pool.run_ordered(items, jobs, row_fn, init_fn, error_row=None)#

Yield row_fn(item) for every item, in input order, computed in jobs spawn workers.

row_fn and init_fn must be importable module-level functions (spawn pickles them by name). An item whose row kills its worker when it runs alone yields error_row(item), or raises BrokenProcessPool when no error_row is given.