Reputation: 3450
I'm trying to run Stanford's CoreNLP using a Python wrapper. When I run the code I get the error message:
Traceback (most recent call last):
File "./corenlp.py", line 257, in <module>
nlp = StanfordCoreNLP()
File "./corenlp.py", line 176, in __init__
self.corenlp.expect("done.", timeout=200) # Loading PCFG (~3sec)
File "/home/user1/anaconda3/envs/user1conda/lib/python3.7/site-packages/pexpect/spawnbase.py", line 344, in expect
timeout, searchwindowsize, async_)
File "/home/user1/anaconda3/envs/user1conda/lib/python3.7/site-packages/pexpect/spawnbase.py", line 372, in expect_list
return exp.expect_loop(timeout)
File "/home/user1/anaconda3/envs/user1conda/lib/python3.7/site-packages/pexpect/expect.py", line 179, in expect_loop
return self.eof(e)
File "/home/user1/anaconda3/envs/user1conda/lib/python3.7/site-packages/pexpect/expect.py", line 122, in eof
raise exc
pexpect.exceptions.EOF: End Of File (EOF). Exception style platform.
<pexpect.pty_spawn.spawn object at 0x7fde11758350>
command: /home/user1/anaconda3/envs/user1conda/bin/java
args: ['/home/user1/anaconda3/envs/user1conda/bin/java', '-Xmx1800m', '-cp', './stanford-corenlp-python/stanford-corenlp-full-2018-10-05/stanford-corenlp-3.9.2.jar:./stanford-corenlp-python/stanford-corenlp-full-2018-10-05/stanford-corenlp-3.9.2-models.jar:./stanford-corenlp-python/stanford-corenlp-full-2018-10-05/joda-time.jar:./stanford-corenlp-python/stanford-corenlp-full-2018-10-05/xom.jar:./stanford-corenlp-python/stanford-corenlp-full-2018-10-05/jollyday.jar', 'edu.stanford.nlp.pipeline.StanfordCoreNLP', '-props', 'default.properties']
buffer (last 100 chars): b''
before (last 100 chars): b'rdCoreNLP.java:188)\r\n\tat edu.stanford.nlp.pipeline.StanfordCoreNLP.main(StanfordCoreNLP.java:1388)\r\n'
after: <class 'pexpect.exceptions.EOF'>
match: None
match_index: None
exitstatus: None
flag_eof: True
pid: 28826
child_fd: 5
closed: False
timeout: 30
delimiter: <class 'pexpect.exceptions.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
searcher: searcher_re:
0: re.compile(b'done.')
I've tried looking at some other answers here, but wasn't able to find a solution to my problem. This question from two years ago is on the same lines of mine, but has no answers.
What might be some things I could try? Thanks.
Upvotes: 2
Views: 882
Reputation: 3034
this error arises simply either when
the following has wrong expectation, so EOF error comes
import pexpect
child = pexpect.spawn('echo hello')
# or on windows
# from pexpect import popen_spawn
# child = pexpect.popen_spawn.PopenSpawn('echo hello')
child.expect("hey") # expected vs reality, and comes the EOF error
the following code consumes the stream then gets the error
import pexpect
child = pexpect.spawn('echo hello')
# or on windows
# from pexpect import popen_spawn
# child = pexpect.popen_spawn.PopenSpawn('echo hello')
child.expect("hello") # consume first worst
child.expect("") # comsume nothing, can be multiple, won't affect
child.expect("\n") # consume end of line
child.expect("\n") # now there is no more char to consume, then comes error
if the current stream is ended, that means either the spawned process ended or it expects some input to continue, where you will proceed with a send/write operation.
there are also \r
, \r\n
and \n
differences depending on the program spawned. The last two can both be matched with \n
(new line) but if they use \r
(carriage return) only then the error will arise. I heard Mac programs may also use \f
(form feed) instead, so heads up.
By the way, pexpect
allows you to automate what would you normally do manually by hand. So be sure to check the version of the application and note what exactly it prints to the screen, and what it expects in return from the user. Version differences are a pretty common source of errors.
PS: I admit I didn't check for what is this "Exception style platform" part of the error. What I would suggest is to first check the above 2 possibilities, then start panicking :)
Upvotes: 0
Reputation: 34551
As per the documentation:
Special EOF and TIMEOUT patterns
There are two special patterns to match the End Of File (
EOF
) or a Timeout condition (TIMEOUT
). You can pass these patterns toexpect()
. These patterns are not regular expressions. Use them like predefined constants.If the child has died and you have read all the child’s output then ordinarily
expect()
will raise anEOF
exception. You can read everything up to the EOF without generating an exception by using theEOF
pattern expect.
Also, from the same documentation:
Exceptions
- End Of File (EOF) in read(). Exception style platform.
- End Of File (EOF) in read(). Empty string style platform.
Some UNIX platforms will throw an exception when you try to read from a file descriptor in the EOF state. Other UNIX platforms instead quietly return an empty string to indicate that the EOF state has been reached.
If you wish to read up to the end of the child’s output without generating an
EOF
exception, then use theexpect(pexpect.EOF)
method.
Upvotes: 0