Skip to content

A fast, helpful, and open-source document parser

cleanup

Logan Markewichbc1b995e99f8
diff --git a/packages/node/README.md b/packages/node/README.md
index 89efb71..8bbc4e3 100644
--- a/packages/node/README.md
+++ b/packages/node/README.md
@@ -166,9 +166,10 @@ console.log(result.text);
PDFium is not thread-safe, so all parses inside one process serialize on a
process-global lock — even `Promise.all` over multiple `parse()` calls runs
-them one at a time. And a parse stuck inside a single PDFium call cannot be
-interrupted from within the process. For high-throughput services, run parses
-in a pool of persistent worker processes instead:
+them one at a time.
+
+For high-throughput services, or for cases when you need to enforce a
+runtime timeout, run parses in a pool of persistent worker processes instead:
```typescript
import { LiteParse, ParseTimeoutError } from '@llamaindex/liteparse';
@@ -187,22 +188,6 @@ try {
parser.close(); // frees workers immediately; an idle pool never blocks exit
```
-- **Real parallelism**: each worker has its own PDFium instance, so `poolSize`
- parses run genuinely concurrently — `Promise.all` becomes actually parallel
- with no caller changes.
-- **Hard kill-switch**: `parseTimeoutMs` is enforced by SIGKILLing the worker
- process (and forking a replacement), so a timed-out parse is guaranteed
- dead — no wedged thread holding a lock. The error names the document, so
- rogue files identify themselves in your logs.
-- **Low overhead**: workers are forked once and reused. Per-parse overhead is
- IPC serialization only (sub-millisecond for small documents).
-
-`parseTimeoutMs` requires `poolSize` by design: an in-process deadline cannot
-actually stop a parse, and LiteParse won't offer a timeout it can't enforce.
-(`worker_threads` wouldn't help either — workers share the process and its
-PDFium lock, and `terminate()` cannot preempt native code.) Only `parse()` is
-routed through the pool; other methods run in-process.
-
## Screenshots
Generate PNG screenshots of document pages:
diff --git a/packages/node/src/lib.ts b/packages/node/src/lib.ts
index e48ad97..709f1d5 100644
--- a/packages/node/src/lib.ts
+++ b/packages/node/src/lib.ts
@@ -26,23 +26,14 @@ export type ImageMode = "off" | "placeholder" | "embed";
/** Options for pool mode: parsing in persistent, killable worker processes. */
export interface PoolOptions {
/**
- * Route `parse()` through a pool of this many persistent worker processes
- * instead of parsing in-process. Each worker has its own PDFium instance,
- * so pooled parses run genuinely in parallel — in-process parses (including
- * concurrent `parse()` promises) serialize on a process-global PDFium lock
- * — and a stuck document can be killed without leaking a wedged thread.
- * Workers are forked once and reused; per-parse overhead is IPC
- * serialization only. Only `parse()` is routed through the pool; other
- * methods still run in-process. Call `close()` when done (an idle pool
- * never keeps the event loop alive, but explicit shutdown frees workers
- * immediately).
+ * Route `parse()` through a pool of this many persistent worker processes.
+ * Call `close()` when done (an idle pool never keeps the event loop alive,
+ * but explicit shutdown frees workers immediately).
*/
poolSize?: number;
/**
- * Hard per-parse deadline in milliseconds. Requires `poolSize`: a deadline
- * is only honest when it can actually stop the work, and an in-process
- * parse stuck inside a single PDFium FFI call cannot be interrupted — the
- * pool enforces the deadline by SIGKILLing the worker process. On expiry
+ * Hard per-parse deadline in milliseconds. Requires `poolSize`.
+ * The pool enforces the deadline by SIGKILLing the worker. On expiry
* the parse rejects with {@link ParseTimeoutError} (naming the document)
* and a fresh worker replaces the killed one.
*/
@@ -685,11 +676,7 @@ export class LiteParse {
userConfig.poolSize === undefined
) {
throw new Error(
- "parseTimeoutMs requires poolSize: an in-process parse stuck inside " +
- "a PDFium call cannot be interrupted, so a timeout without process " +
- "isolation would be a promise LiteParse cannot keep. Set poolSize " +
- "(e.g. poolSize: 1) to enforce the deadline by killing the worker " +
- "process.",
+ "parseTimeoutMs requires poolSize"
);
}
if (userConfig.poolSize !== undefined) {
diff --git a/packages/node/src/pool-worker.ts b/packages/node/src/pool-worker.ts
index bae1cd5..69c103c 100644
--- a/packages/node/src/pool-worker.ts
+++ b/packages/node/src/pool-worker.ts
@@ -1,10 +1,4 @@
// Entry point for pool worker processes, forked by pool.ts.
-//
-// Each worker holds its own native LiteParse instance — and therefore its own
-// PDFium instance and PDFium lock — so pooled parses run genuinely in
-// parallel and a stuck parse can be killed by killing this process. The
-// parent speaks over the fork() IPC channel (advanced serialization), one
-// request in flight at a time.
import { native, type LiteParseNative } from "./native.js";
import { toParseResult } from "./lib.js";
diff --git a/packages/node/src/pool.ts b/packages/node/src/pool.ts
index 5b7fa84..dc24bf5 100644
--- a/packages/node/src/pool.ts
+++ b/packages/node/src/pool.ts
@@ -1,14 +1,5 @@
// Process-isolated worker pool for LiteParse.
//
-// PDFium work happens behind a process-global lock, and a single PDFium FFI
-// call cannot be interrupted from inside the process — worker_threads would
-// not help (same process, same lock, and terminate() cannot preempt native
-// code). The only enforceable timeout is a process boundary: parses run in
-// forked worker processes (see pool-worker.ts), and a worker that blows its
-// deadline is SIGKILLed and replaced. Because each worker has its own PDFium,
-// pooled parses also run genuinely in parallel instead of queueing on the
-// lock.
-//
// Not public API; use `new LiteParse({ poolSize, parseTimeoutMs })`.
import { fork, type ChildProcess } from "node:child_process";
diff --git a/packages/python/README.md b/packages/python/README.md
index c01a489..bda9b6f 100644
--- a/packages/python/README.md
+++ b/packages/python/README.md
@@ -117,9 +117,8 @@ print(result.text)
## Worker Pool and Hard Timeouts
PDFium is not thread-safe, so in-process parses serialize on a process-global
-lock — and a parse stuck inside a single PDFium call cannot be interrupted
-from within the process. For high-throughput services, run parses in a pool
-of persistent worker processes instead:
+lock. For high-throughput services, or cases where you need to enforce a timeout,
+run parses in a pool of persistent worker processes instead:
```python
from liteparse import LiteParse, ParseTimeoutError
@@ -135,19 +134,6 @@ except ParseTimeoutError as e:
parser.close() # or use `with LiteParse(...) as parser:`
```
-- **Real parallelism**: each worker has its own PDFium instance, so `pool_size`
- parses run genuinely concurrently instead of queueing on the global lock.
-- **Hard kill-switch**: `parse_timeout` is enforced by killing the worker
- process (and spawning a replacement), so a timed-out parse is guaranteed
- dead — no wedged thread holding a lock. The exception names the document,
- so rogue files identify themselves in your logs.
-- **Low overhead**: workers are spawned once and reused. Per-parse overhead is
- IPC serialization only (sub-millisecond for small documents).
-
-`parse_timeout` requires `pool_size` by design: an in-process deadline cannot
-actually stop a parse, and LiteParse won't offer a timeout it can't enforce.
-Only `parse()` is routed through the pool; other methods run in-process.
-
## Screenshots
Generate PNG screenshots of document pages:
diff --git a/packages/python/liteparse/_pool.py b/packages/python/liteparse/_pool.py
index b7b83bc..b8d8416 100644
--- a/packages/python/liteparse/_pool.py
+++ b/packages/python/liteparse/_pool.py
@@ -1,27 +1,5 @@
"""Process-isolated worker pool for LiteParse.
-PDFium work happens behind a process-global lock, and a single PDFium FFI
-call cannot be interrupted from inside the process — a thread stuck in one
-holds the lock until the call returns, no matter what deadline the caller
-wanted. The only enforceable timeout is a process boundary: run parses in
-dedicated worker processes and kill a worker outright when it blows its
-deadline.
-
-This module implements that boundary:
-
-- Each worker is a subprocess running ``python -m liteparse._pool`` with its
- own native LiteParse instance (and therefore its own PDFium instance and
- its own PDFium lock). Workers are persistent — spawn and import cost is
- paid once per worker, not per parse.
-- Requests and responses are pickled frames over the worker's stdin/stdout.
- The worker's real stdout is reserved for the protocol; fd 1 is redirected
- to stderr immediately so stray prints (native progress logs, user hooks)
- cannot corrupt it.
-- A parse that exceeds ``parse_timeout`` gets its worker SIGKILLed and a
- replacement spawned; the caller receives :class:`ParseTimeoutError` naming
- the document. Because each worker has its own PDFium, one stuck document
- never blocks the others (no cross-worker lock convoy).
-
The pool is not public API; use ``LiteParse(pool_size=..., parse_timeout=...)``.
"""
diff --git a/packages/python/liteparse/parser.py b/packages/python/liteparse/parser.py
index b34d68f..cd83ccd 100644
--- a/packages/python/liteparse/parser.py
+++ b/packages/python/liteparse/parser.py
@@ -572,21 +572,10 @@ class LiteParse:
merged horizontal/vertical line segments. Default False.
pool_size: Route :meth:`parse` through a pool of this many
persistent worker processes instead of parsing in-process.
- Each worker has its own PDFium instance, so pooled parses run
- genuinely in parallel (in-process parses serialize on a
- process-global PDFium lock) and a stuck document can be
- killed without leaking a wedged thread. Workers are spawned
- once and reused; per-parse overhead is IPC serialization
- only. Other methods (:meth:`parse_batches`,
- :meth:`is_complex`, :meth:`screenshot`) still run in-process.
Call :meth:`close` (or use ``with``) to shut workers down.
parse_timeout: Hard per-parse deadline in seconds. Requires
- ``pool_size``: a deadline is only honest when it can actually
- stop the work, and an in-process parse stuck inside a single
- PDFium FFI call cannot be interrupted — the pool enforces the
- deadline by killing the worker process. On expiry the parse
- raises :class:`ParseTimeoutError` (naming the document) and a
- fresh worker replaces the killed one.
+ ``pool_size``: On expiry the parse raises :class:`ParseTimeoutError`
+ (naming the document) and a fresh worker replaces the killed one.
"""
kwargs = {}
if ocr_enabled is not None:
@@ -668,11 +657,7 @@ class LiteParse:
if parse_timeout is not None and pool_size is None:
raise ValueError(
- "parse_timeout requires pool_size: an in-process parse stuck "
- "inside a PDFium call cannot be interrupted, so a timeout "
- "without process isolation would be a promise LiteParse "
- "cannot keep. Set pool_size (e.g. pool_size=1) to enforce "
- "the deadline by killing the worker process."
+ "parse_timeout requires pool_size"
)
self._pool = None
if pool_size is not None: