python-stanford-corenlp icon indicating copy to clipboard operation
python-stanford-corenlp copied to clipboard

Timeout problem

Open saurabh0vipin opened this issue 6 years ago • 11 comments
trafficstars

getting this error ReadTimeout(e, request=request) requests.exceptions.ReadTimeout: HTTPConnectionPool(host='localhost', port=9000): Read timed out. (read timeout=30) when tried to execute import corenlp text = "Chris wrote a simple sentence that he parsed with Stanford CoreNLP." with corenlp.CoreNLPClient(annotators="tokenize ssplit pos lemma ner depparse".split()) as client: ann = client.annotate(text) sentence = ann.sentence[0] assert corenlp.to_text(sentence) == text print(sentence.text)

saurabh0vipin avatar Jan 24 '19 08:01 saurabh0vipin

I faced this as well. Please suggest a fix!

AgoloKushagraGoyal avatar Jan 28 '19 16:01 AgoloKushagraGoyal

This could happen if you didn't start the CoreNLP server before calling it from Python. For help with starting the CoreNLP server, see: https://stanfordnlp.github.io/CoreNLP/corenlp-server.html

qipeng avatar Jan 28 '19 17:01 qipeng

started server before calling it on the same port number tried both with large time out like 1500000 and without mannual timeout taking as default value.

saurabh0vipin avatar Jan 28 '19 18:01 saurabh0vipin

Hmmm... it's a bit hard to debug with just the information you've provided:

(a) do you have the latest version of the library (3.9.2)?

(b) When running, can you set "be_quiet=False" on the client, e.g. with corenlp.CoreNLPClient(annotators="tokenize ssplit pos lemma ner depparse".split(), be_quiet=False) as client and share what messages you get from the Java process?

On Mon, Jan 28, 2019 at 10:34 AM Saurabh Verma [email protected] wrote:

started server before calling it on the same port number tried both with large time out like 1500000 and without mannual timeout taking as default value.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/stanfordnlp/python-stanford-corenlp/issues/29#issuecomment-458248666, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFOyZGq9coIpRATaqtLHPA-o-HHqVZqks5vH0KlgaJpZM4aQaUZ .

-- Arun Tejasvi Chaganty http://arun.chagantys.org/

arunchaganty avatar Jan 29 '19 05:01 arunchaganty

getting this error ReadTimeout(e, request=request) requests.exceptions.ReadTimeout: HTTPConnectionPool(host='localhost', port=9000): Read timed out. (read timeout=30) when tried to execute import corenlp text = "Chris wrote a simple sentence that he parsed with Stanford CoreNLP." with corenlp.CoreNLPClient(annotators="tokenize ssplit pos lemma ner depparse".split()) as client: ann = client.annotate(text) sentence = ann.sentence[0] assert corenlp.to_text(sentence) == text print(sentence.text)

Set the timeout parameter in the CoreNLPClient constructor. i.e.

corenlp.CoreNLPClient(timeout=30000,annotators=...)

The timeout you are experiencing is the client http request, not the server.

Note that confusingly the timeout is in 2ms units! The value you provide is multiplied by 2 and then divided by 1000 before being passed to Python request module.... https://github.com/stanfordnlp/python-stanford-corenlp/blob/01a60b7eb816435c39768ff90e822aba43821229/corenlp/client.py#L199

So in the above example using a timeout of 30000 means 60 seconds

edited - not annotate function

greasystrangler avatar Jan 31 '19 22:01 greasystrangler

Ah, I think the *2 was intentional in that I wanted to provide additional buffer to the HTTP request to make sure it didn't timeout before CoreNLP did (and the ms -> sec conversion is because of a difference in units between CoreNLP and the requests module).

The concern is why is the HTTP client timing out? It would be very helpful to see the messages outputted by the CoreNLP server -- one possibility is that the first utterance takes an exceptionally long time to load because it's loading up all of the models: if that's the case, the best solution for this would be to up the timeout a bit more.

More generally, I would recommend moving over to the new (official) Stanford CoreNLP python library: https://github.com/stanfordnlp/stanfordnlp

On Thu, Jan 31, 2019 at 2:23 PM greasystrangler [email protected] wrote:

getting this error ReadTimeout(e, request=request) requests.exceptions.ReadTimeout: HTTPConnectionPool(host='localhost', port=9000): Read timed out. (read timeout=30) when tried to execute import corenlp text = "Chris wrote a simple sentence that he parsed with Stanford CoreNLP." with corenlp.CoreNLPClient(annotators="tokenize ssplit pos lemma ner depparse".split()) as client: ann = client.annotate(text) sentence = ann.sentence[0] assert corenlp.to_text(sentence) == text print(sentence.text)

Set the timeout parameter in the annotate function. i.e.

ann = client.annotate(text, timeout=30000)

The timeout is the client http request, not the server.

Note that confusingly the timeout is in 2ms units! The value you provide is multiplied by 2 and then divided by 1000 before being passed to Python request module....

https://github.com/stanfordnlp/python-stanford-corenlp/blob/01a60b7eb816435c39768ff90e822aba43821229/corenlp/client.py#L199

So in the above example using a timeout of 30000 means 60 seconds

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/stanfordnlp/python-stanford-corenlp/issues/29#issuecomment-459529805, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFOydqyNfsZ52y6tf3tueX3uEU3fJRwks5vI2zggaJpZM4aQaUZ .

-- Arun Tejasvi Chaganty http://arun.chagantys.org/

arunchaganty avatar Feb 07 '19 08:02 arunchaganty

This could happen if you didn't start the CoreNLP server before calling it from Python. For help with starting the CoreNLP server, see: https://stanfordnlp.github.io/CoreNLP/corenlp-server.html

After doing this, you also have to open this in a tab as well : http://localhost:9000/ This worked for me.

abhiram11 avatar Nov 25 '19 07:11 abhiram11

Hmmm... it's a bit hard to debug with just the information you've provided: (a) do you have the latest version of the library (3.9.2)? (b) When running, can you set "be_quiet=False" on the client, e.g. with corenlp.CoreNLPClient(annotators="tokenize ssplit pos lemma ner depparse".split(), be_quiet=False) as client and share what messages you get from the Java process? On Mon, Jan 28, 2019 at 10:34 AM Saurabh Verma @.***> wrote: started server before calling it on the same port number tried both with large time out like 1500000 and without mannual timeout taking as default value. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#29 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFOyZGq9coIpRATaqtLHPA-o-HHqVZqks5vH0KlgaJpZM4aQaUZ . -- Arun Tejasvi Chaganty http://arun.chagantys.org/

I still meet this issue, but in a different situation. With setting be_quiet=False, I printed the details:

[main] INFO CoreNLP - --- StanfordCoreNLPServer#main() called --- .... [main] INFO CoreNLP - Starting server... [main] INFO CoreNLP - StanfordCoreNLPServer listening at /0:0:0:0:0:0:0:0:3220

After waiting, I got the following error with Traceback:

Traceback (most recent call last): doc = client.annotate(text) r = self._request(text.encode('utf-8'), request_properties, **kwargs) self.ensure_alive() raise PermanentlyFailedException("Timed out waiting for service to come alive.") stanfordnlp.server.client.PermanentlyFailedException: Timed out waiting for service to come alive.

It seems the request has not responded. How can I fix it? Any ideas?

LiuYuLOL avatar Apr 25 '20 23:04 LiuYuLOL

We have no idea what you're doing, so probably hard to get good suggestions. However, it looks like you're running the server on port 3220. Are you also setting the client to use that port?

AngledLuffa avatar Apr 25 '20 23:04 AngledLuffa

We have no idea what you're doing, so probably hard to get good suggestions. However, it looks like you're running the server on port 3220. Are you also setting the client to use that port?

I try to use CoreNLP to do some annotations under the python environment using pycharm.

Yes. Port 3220 is just randomly selected. I also tested with default port 9000, but doesn't work. Below is my code.

    with CoreNLPClient(
            endpoint='http://localhost:3220',
            memory='4G',
            annotators=['tokenize', 'ssplit', 'pos', 'lemma', 'ner'],
            timeout=50000, be_quiet=False) as client:
        text = 'this is a text file.'
        doc = client.annotate(text)

I check the listening ports, using netstat -l and both ports are free.

I also tested on stanza, but it still returns the same error.

LiuYuLOL avatar Apr 26 '20 00:04 LiuYuLOL

A good idea is to check the permissions as https://github.com/stanfordnlp/stanza/issues/245#issuecomment-617437964

Any idea to see my permissions on the server?

LiuYuLOL avatar Apr 26 '20 00:04 LiuYuLOL