Stop the CoreNLP server if a test connection to it cannot be established #3430
+25
−19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The method
start
of classCoreNLPServer
from modulenltk.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.