orthonym.cli_time_limit#
Note
Internal API. Names and behaviour may change between releases.
--time-limit of the command line: a wall-clock limit on the naming of each structure.
A few slow structures in a large --batch file hold up the whole run, and a limit of the caller’s
own (a thread that waits, a signal.alarm whose handler raises an Exception) does not stop
naming: the naming path holds hundreds of except Exception handlers, and a thread cannot be
stopped. --time-limit SECONDS arms:func:orthonym.wallclock.wall_clock_limit around the naming
of each structure. A structure that is not named within the limit is a decline of its own, with the
reason code TIME_LIMIT, and the run goes on with the next line, which is named as in a fresh
process (the limit puts the process-global naming state back, and the batch builds a new
Orthonym after a timeout).
What the limit does not do. The alarm is a SIGALRM handler, and Python runs a handler only when
the main thread is back in Python. A call that has not returned yet, into the JVM (OPSIN, the
centres labeller) or into RDKit, runs to its end first, so the limit can be exceeded by the length of
the one call that was running when it expired. Measured on 168 real structures at limits of 0.05 to
1 s (840 runs, 268 of them timed out): 1.1 ms over the limit in the middle, 10 ms for 99 in 100, 57 ms
at worst; a JVM call was running at the deadline in 12 of them, for 11 ms at most. The calls are short
(the longest JVM call in a naming of 90 s was 0.42 s, the first of the process, which starts the JVM); a
call into a cold JVM is long, so:func:prepare starts the JVM before the first limit is armed, and
jvm_bridge._alarm_held keeps an alarm out of the one call into the JVM that cannot be interrupted
(startJVM). OPSIN needs 2 s for a made-up name of 3,600 characters.
A call that lasts much longer is the case the alarm cannot serve, and it was met: a polyphenylene of 37
benzene rings (GitHub issue 121, the two dendrimers of C222H150 and C258H174) sent a ring-only fragment of
222 atoms to the cage analysis of vonbaeyer_universal, which starts by matching the fragment onto its own
canonical re-parse (Mol.GetSubstructMatch, a VF2 search that grows with the symmetry of the branches and
refuses the fragment only after it); the match ran for more than ten minutes in one call, with the alarm
of --time-limit 850 pending (both runs were ended by an outer timeout 900). That call is no longer
made for rings that are joined by bonds (ring_cluster.is_one_ring_cluster), and the structures are named
in about five seconds. For a run of ONE structure,:func:on_hard_stop is the net for the next call of this
kind: the run ends:data:HARD_STOP_GRACE_S seconds after the limit with the outcome of any other timeout (a
thread cannot stop the call, and does not need to: the process is over). A --batch run has no net: the
lines after a call that does not return would wait for it.
Where no alarm can be set (a platform without SIGALRM, a command line run from a thread other
than the main one),:func:prepare says so once on the error stream and the run goes on without a
limit.
- orthonym.cli_time_limit.CODE = 'TIME_LIMIT'#
The reason code of a structure that was not named within the limit. It says something about the run, not about the structure, so it is not a key of
errors.LIMIT_CATALOG(asINVALID_SMILESis not).
- orthonym.cli_time_limit.HARD_STOP_GRACE_S = 5.0#
A run of one structure that is still in the call it was in when the limit expired this long after it (the alarm cannot be handled until the call returns) ends with the outcome of a timeout (
on_hard_stop()).
- orthonym.cli_time_limit.REFIRE_S = 0.1#
The alarm that was lost is raised again after this long (
wall_clock_limit(refire=...); the default of the measurement tools is 1 s). A first alarm that lands in aWeakKeyDictionarycallback is dropped, and the naming would run on for a second more.
- orthonym.cli_time_limit.WARM_UP_SMILES = 'C[C@H](N)C(=O)O'#
A small structure with a stereocentre, named once before the first limit is armed so that the one-time start-up costs (the JVM, OPSIN’s parse tables, the centres labeller, the naming modules imported on first use) are not paid under a limit.
- orthonym.cli_time_limit.add_option(parser)#
- orthonym.cli_time_limit.error(smiles, seconds)#
The limit that
--on-failure raiseraises for a structure that ran out of time.
- orthonym.cli_time_limit.label(seconds)#
The label of a structure that ran out of time: what
--on-failure labelprints in place of a name.
- orthonym.cli_time_limit.limit(seconds)#
The wall-clock limit of
seconds(none when None) as awithblock: raisesorthonym.wallclock.WallClockTimeoutwhen the body runs out of it, with the naming state put back.
- orthonym.cli_time_limit.on_hard_stop(callback, status=0)#
Register (
Noneclears) what ends a run of ONE structure whose call has not returned:data:HARD_STOP_GRACE_S seconds after its limit:callbackprints the outcome of a timeout and returns the exit status;statusis the status of the run when the callback raises (the status of a timeout of that run), so that the process ends whatever the callback does.
- orthonym.cli_time_limit.prepare(seconds, style, emit_tier, warm_up=True)#
The limit this run can enforce:
seconds, or None for no limit (not asked for, or no alarm can be set here, which is said once on the error stream). When there is a limit, the start-up costs of naming are paid first (see:data:WARM_UP_SMILES), outside any limit; not withwarm_upFalse (the parent of--jobsworkers, which names nothing: each worker warms itself up).A timeout while the JVM is starting is not harmless: the first structure would be charged the start-up (about a second), and the structure that follows would depend on where in the start-up the alarm landed.
- orthonym.cli_time_limit.row(smiles, seconds)#
The
--provenancerow of a structure that ran out of time: the keys ofOrthonym.name_tiered, tierabstain(no name),limit_codeTIME_LIMITand the final check asnot_run.
- orthonym.cli_time_limit.seconds_arg(value)#
--time-limitvalue: a number of seconds above 0.
- orthonym.cli_time_limit.timed(seconds, fn, *args, **kwargs)#
fn(*args, **kwargs)under:func:limit (and the net of:func:on_hard_stop, when a run of one structure set it).