+
Skip to content

Conversation

asrelo
Copy link
Contributor

@asrelo asrelo commented Oct 1, 2025

The method start of class CoreNLPServer from module nltk.parse.corenlp launches a CoreNLP server as a separate process and then checks its status: 1. by a test for premature exit, 2. by poking some of its endpoints repeatedly.

If any of the endpoints test fails, an exception is raised. However, the server process is not shut down; and as the popen attribute of the class does not appear to be the part of intended public interface, the track of the started server process is lost. This causes a resources leak, primarily from potential bound to the given network port.

This PR makes it so the server process is terminated if a test connection to it cannot be established to avoid the resources leak. It does not even wait on the process to terminate, just sends the signal.

This is an opinionated change; some would consider leaving the process up for investigation by user instead (i.e. leaving the code as is), or leaving an option to do it, or even exposing the process as part of interface.

@ekaf
Copy link
Member

ekaf commented Oct 2, 2025

This PR improves the reliability of CoreNLP server startup by ensuring that failed launches are properly cleaned up. It looks good to merge as it is.

For completeness, here are a few possible future enhancements (none of which are blocking for this PR): more thorough tests for process termination, configurable timeouts, concurrency safety, and additional logging.

I also note that two new issues (#3428 and #3429) have been opened by the same author regarding CoreNLP startup problems:

While this PR addresses cleanup specifically, the issues raised in #3428 and #3429—regarding port detection and startup timing—seem closely related. Coordinating future fixes for these CoreNLP startup aspects may be worthwhile, but merging this PR independently makes sense.

Thanks for helping to improve CoreNLP integration in NLTK!

@stevenbird
Copy link
Member

Thanks @asrelo! And for your feedback @ekaf.

@stevenbird stevenbird merged commit 7508653 into nltk:develop Oct 3, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载