Skip to content

analyze() takes a timeout - #47

Merged
ddehilster merged 1 commit into
VisualText:mainfrom
ddehilster:feat/analyze-takes-a-timeout
Oct 27, 2026
Merged

ddehilster merged 1 commit into
VisualText:mainfrom
ddehilster:feat/analyze-takes-a-timeout

Conversation

@ddehilster

Copy link
Copy Markdown
Member

An NLP++ analyzer whose loop never ends could only be stopped by killing the process. One that makes a new string every turn gets there by itself, by running out of memory: in production, one such grammar took a document extractor down five times in half an hour. Engine 4.2.41 (VisualText/nlp-engine#800, released in 4.2.42 / NLPPlus 2.2.73) can stop a run at a time limit. This passes the limit through.

API

  • Engine.analyze(..., timeout=seconds) and NLPPlus.analyze(..., timeout=). None, the default, means no limit, as before.
  • A run stopped at the limit raises AnalysisStopped, which carries the analyzer name and the timeout. It's an EngineException and also an Exception, so ordinary except Exception handling catches it. EngineException alone wouldn't be caught, because it derives from BaseException.
  • The binding takes timeout in analyze() and exposes last_run_stopped().

The engine stops the run at its next while turn or pass, skips the passes after it, and frees what it built, so the same Engine is fit for the next call.

Tests: TimeoutTest builds a throwaway analyzer that loops forever, and checks that:

  • it's stopped within the limit;
  • AnalysisStopped is raised and is an Exception;
  • the pass after the loop didn't run;
  • the same Engine then runs an analyzer that finishes, with and without a timeout.

Run locally against this engine on Windows, all three pass. The four other tests that fail locally (test_simple, test_emailaddress_parser, test_repeated_analyze_same_process, test_multibyte_words_survive_single_byte_locale) fail the same way on an unmodified main built the same way, so they're about the local environment, not this change. CI here is the real check.

🤖 Generated with Claude Code

ddehilster added a commit to ddehilster/py-package-nlpengine that referenced this pull request Oct 27, 2026
package-analyzers a53e9e2 and the zone rework now split "kenethfpp at
mails dot yahoo dot uk" into subdomain/domainname/cd and keep the local
part of "charitysc123 at 243 dot org". The stored output predated both,
so test_emailaddress_parser failed on every PR (also VisualText#47). Regenerated
with nlp 4.2.48 and the pinned package-analyzers commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An NLP++ analyzer whose loop never ends could only be stopped by killing
the process, and one that makes a string a turn got there by itself, out
of memory. Engine 4.2.41 can stop a run at a limit; this passes one
through.

- Engine.analyze(..., timeout=seconds) and NLPPlus.analyze(...,
  timeout=). None, the default, is no limit, as before.
- A run stopped at it raises AnalysisStopped, which carries the analyzer
  name and the timeout. It is an EngineException and also an Exception,
  so ordinary error handling catches it, which EngineException alone
  (a BaseException) does not.
- The binding takes timeout in analyze() and exposes last_run_stopped().

TimeoutTest builds a throwaway analyzer that loops forever: it is
stopped, the pass after it does not run, and the same Engine then runs
an analyzer that finishes, with and without a timeout.

Needs the nlp-engine submodule at 4.2.41 or later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ddehilster
ddehilster force-pushed the feat/analyze-takes-a-timeout branch from c7afa9d to 5888838 Compare October 27, 2026 18:58
@ddehilster
ddehilster merged commit 5342351 into VisualText:main Oct 27, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant