Skip to content

Fix concurrent calls to the Japanese tokenizer - #14086

Open
emme1t wants to merge 1 commit into
explosion:masterfrom
emme1t:fix/japanese-tokenizer-concurrent-calls
Open

emme1t wants to merge 1 commit into
explosion:masterfrom
emme1t:fix/japanese-tokenizer-concurrent-calls

Conversation

@emme1t

@emme1t emme1t commented Nov 21, 2026 •

Copy link
Copy Markdown

Description

Fixes #13733. SudachiPy releases the GIL during tokenization. Concurrent calls through the same Japanese pipeline can then raise RuntimeError: Already borrowed in SudachiPy 0.6 or SudachiError: Tokenizer is already in use in 0.7.

Acquire a lock per JapaneseTokenizer around the native tokenize() call. Each caller converts its own morphemes to a Doc after releasing the lock. The regression test starts five threads together and compares their token boundaries with serial results.

Tests

On Windows with Python 3.12.13, the regression test reproduced the exception on master with SudachiPy 0.6.10 and 0.7.0. The Japanese language suite passed with each version after the fix (122 passed, 2 existing skips per run). The tests used the Japanese tokenizer and test files from this checkout with the native extensions from the spaCy 3.8.18 wheel.

Types of change

Bug fix.

Checklist

  • I confirm that I have the right to submit this contribution under the project's MIT license.
  • I ran the tests, and all new and existing tests passed.
  • My changes don't require a change to the documentation, or if they do, I've added all required information.

This branch has not been deployed

No deployments
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.

Japanese TokenizerRuntimeError: Already borrowed

1 participant