From bec8db91e6b8aa8c64a24ac6562c9a8aaf639a13 Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Fri, 15 Mar 2019 16:38:44 +0100 Subject: [PATCH] Add actual deprecation warning for n_threads (resolves #3410) --- spacy/errors.py | 4 ++++ spacy/language.py | 2 ++ spacy/matcher/matcher.pyx | 4 +++- spacy/matcher/phrasematcher.pyx | 2 ++ spacy/tests/regression/test_issue3410.py | 21 +++++++++++++++++++++ spacy/tokenizer.pyx | 2 ++ 6 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 spacy/tests/regression/test_issue3410.py diff --git a/spacy/errors.py b/spacy/errors.py index 0ccff4c75..1fca7060b 100644 --- a/spacy/errors.py +++ b/spacy/errors.py @@ -76,6 +76,10 @@ class Warnings(object): W015 = ("As of v2.1.0, the use of keyword arguments to exclude fields from " "being serialized or deserialized is deprecated. Please use the " "`exclude` argument instead. For example: exclude=['{arg}'].") + W016 = ("The keyword argument `n_threads` on the is now deprecated, as " + "the v2.x models cannot release the global interpreter lock. " + "Future versions may introduce a `n_process` argument for " + "parallel inference via multiprocessing.") @add_codes diff --git a/spacy/language.py b/spacy/language.py index 48ba17218..ec365e12b 100644 --- a/spacy/language.py +++ b/spacy/language.py @@ -666,6 +666,8 @@ class Language(object): DOCS: https://spacy.io/api/language#pipe """ + if n_threads != -1: + deprecation_warning(Warnings.W016) if as_tuples: text_context1, text_context2 = itertools.tee(texts) texts = (tc[0] for tc in text_context1) diff --git a/spacy/matcher/matcher.pyx b/spacy/matcher/matcher.pyx index 7abe42843..37218ce0d 100644 --- a/spacy/matcher/matcher.pyx +++ b/spacy/matcher/matcher.pyx @@ -19,7 +19,7 @@ from ..attrs cimport ID, attr_id_t, NULL_ATTR, ORTH from ._schemas import TOKEN_PATTERN_SCHEMA from ..util import get_json_validator, validate_json -from ..errors import Errors, MatchPatternError +from ..errors import Errors, MatchPatternError, Warnings, deprecation_warning from ..strings import get_string_id from ..attrs import IDS @@ -160,6 +160,8 @@ cdef class Matcher: batch_size (int): Number of documents to accumulate into a working set. YIELDS (Doc): Documents, in order. """ + if n_threads != -1: + deprecation_warning(Warnings.W016) for doc in docs: self(doc) yield doc diff --git a/spacy/matcher/phrasematcher.pyx b/spacy/matcher/phrasematcher.pyx index ddf6e8cce..22ce8831a 100644 --- a/spacy/matcher/phrasematcher.pyx +++ b/spacy/matcher/phrasematcher.pyx @@ -182,6 +182,8 @@ cdef class PhraseMatcher: DOCS: https://spacy.io/api/phrasematcher#pipe """ + if n_threads != -1: + deprecation_warning(Warnings.W016) if as_tuples: for doc, context in stream: matches = self(doc) diff --git a/spacy/tests/regression/test_issue3410.py b/spacy/tests/regression/test_issue3410.py new file mode 100644 index 000000000..5d2ac5ba3 --- /dev/null +++ b/spacy/tests/regression/test_issue3410.py @@ -0,0 +1,21 @@ +# coding: utf8 +from __future__ import unicode_literals + +import pytest +from spacy.lang.en import English +from spacy.matcher import Matcher, PhraseMatcher + + +def test_issue3410(): + texts = ["Hello world", "This is a test"] + nlp = English() + matcher = Matcher(nlp.vocab) + phrasematcher = PhraseMatcher(nlp.vocab) + with pytest.deprecated_call(): + docs = list(nlp.pipe(texts, n_threads=4)) + with pytest.deprecated_call(): + docs = list(nlp.tokenizer.pipe(texts, n_threads=4)) + with pytest.deprecated_call(): + list(matcher.pipe(docs, n_threads=4)) + with pytest.deprecated_call(): + list(phrasematcher.pipe(docs, n_threads=4)) diff --git a/spacy/tokenizer.pyx b/spacy/tokenizer.pyx index bec509624..86c2d6ad3 100644 --- a/spacy/tokenizer.pyx +++ b/spacy/tokenizer.pyx @@ -134,6 +134,8 @@ cdef class Tokenizer: DOCS: https://spacy.io/api/tokenizer#pipe """ + if n_threads != -1: + deprecation_warning(Warnings.W016) for text in texts: yield self(text)