stanfordnlp / python-stanford-corenlp

Python interface to CoreNLP using a bidirectional server-client interface.
MIT License
516 stars 105 forks source link

Timeout problem #29

Open saurabh0vipin opened 5 years ago

saurabh0vipin commented 5 years ago

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)

AgoloKushagraGoyal commented 5 years ago

I faced this as well. Please suggest a fix!

qipeng commented 5 years ago

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

saurabh0vipin commented 5 years ago

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.

arunchaganty commented 5 years ago

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 notifications@github.com 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/

greasystrangler commented 5 years ago

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

arunchaganty commented 5 years ago

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 notifications@github.com 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/

abhiram11 commented 5 years ago

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.

LiuYuLOL commented 4 years ago

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?

AngledLuffa commented 4 years ago

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?

LiuYuLOL commented 4 years ago

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 commented 4 years ago

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?