0

I organized my Python Workspace in the following way: the Scripts directory contains the code I'm writing myself; the Modules directory contains third party modules I need to import and use in my code. Here's the representation:

/PythonWorkspace/
     /Scripts
         some_script.py
     /Modules
         __init__.py
         some_module.py
         some_module_DIR

The script some_script.py needs to use the class some_class from some_module.py, so I followed instructions found here and the import works just fine.

To create an object of the class contained in some_module.py I use

some_object = some_class('path to some_module_DIR')

since some_class needs to access the content of some_module_DIR. This causes a very specific error (posted at the end for readability) raised by Pexpect, which is imported by some_module.py.

The weird thing is that if I copy some_script.py into /Modules and run it from there I get no error when creating an object of class some_class. However, in the latter case I use some_object = some_class() since the default path is used in this case.

Questions:

  • What could be the problem?
  • Any suggested fix?

Here is the error I get:

Note: The error contains my original paths and references to the module corenlp that I'm using (a python wrapper for the stanford parser).

In [19]: corenlp = StanfordCoreNLP('./stanfordParserPython/stanford-corenlp-full-2014-08-27/')
---------------------------------------------------------------------------                               
EOF                                       Traceback (most recent call last)
/home/matteorr/Cluster/home/research/SceneUnderstanding/<ipython-input-19-97d07e470ae5> in <module>()
----> 1 corenlp = StanfordCoreNLP('./stanfordParserPython/stanford-corenlp-full-2014-08-27/')

/home/matteorr/Cluster/home/research/SceneUnderstanding/corenlp.pyc in __init__(self, corenlp_path)
    166         widgets = ['Loading Models: ', Fraction()]
    167         pbar = ProgressBar(widgets=widgets, maxval=5, force_update=True).start()
--> 168         self.corenlp.expect("done.", timeout=20) # Load pos tagger model (~5sec)
    169         pbar.update(1)
    170         self.corenlp.expect("done.", timeout=200) # Load NER-all classifier (~33sec)

/usr/lib/python2.7/dist-packages/pexpect.pyc in expect(self, pattern, timeout, searchwindowsize)
   1309 
   1310         compiled_pattern_list = self.compile_pattern_list(pattern)
-> 1311         return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
   1312 
   1313     def expect_list(self, pattern_list, timeout = -1, searchwindowsize = -1):

/usr/lib/python2.7/dist-packages/pexpect.pyc in expect_list(self, pattern_list, timeout, searchwindowsize)
   1323         self.searchwindowsize value is used. """
   1324 
-> 1325         return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)
   1326 
   1327     def expect_exact(self, pattern_list, timeout = -1, searchwindowsize = -1):

/usr/lib/python2.7/dist-packages/pexpect.pyc in expect_loop(self, searcher, timeout, searchwindowsize)
   1394                 self.match = None
   1395                 self.match_index = None
-> 1396                 raise EOF (str(e) + '\n' + str(self))
   1397         except TIMEOUT, e:
   1398             self.buffer = incoming

EOF: End Of File (EOF) in read_nonblocking(). Exception style platform.
<pexpect.spawn object at 0x2a4fdd0>
version: 2.3 ($Revision: 399 $)
command: /usr/bin/java
args: ['/usr/bin/java', '-Xmx1800m', '-cp', './stanfordParserPython/stanford-corenlp-full-2014-08-27/stanford-corenlp-3.4.1.jar:./stanfordParserPython/stanford-corenlp-full-2014-08-27/stanford-corenlp-3.4.1-models.jar:./stanfordParserPython/stanford-corenlp-full-2014-08-27/joda-time.jar:./stanfordParserPython/stanford-corenlp-full-2014-08-27/xom.jar:./stanfordParserPython/stanford-corenlp-full-2014-08-27/jollyday.jar', 'edu.stanford.nlp.pipeline.StanfordCoreNLP', '-props', 'default.properties']
searcher: searcher_re:
    0: re.compile("done.")
buffer (last 100 chars): 
before (last 100 chars): va:448)
    at edu.stanford.nlp.util.StringUtils.argsToProperties(StringUtils.java:869)
    ... 2 more

after: <class 'pexpect.EOF'>
match: None
match_index: None
exitstatus: None
flag_eof: True
pid: 22440
child_fd: 7
closed: False
timeout: 30
delimiter: <class 'pexpect.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
Community
  • 1
  • 1
Matteo
  • 7,924
  • 24
  • 84
  • 129
  • You're giving it a relative path. That's probably relative to where you run the code, not where that class is defined, so it's looking in `.../Scripts/some_module_DIR/` instead of `.../Modules/some_module_DIR/`. The corenlp Python package should probably check if the path you give it exists, and throw a clearer error if it doesn't, rather than just reporting the failure of the Java process. – Thomas K Dec 18 '14 at 00:12
  • @ThomasK - thanks for your reply. I know it seems like the code I run has a relative path different from the directory structure that i described, but it's because I changed that after the question and since I got the same error didn't post the different code. Even if the relative path is the expected one I still get the same error. Any other suggestion? Thanks again! – Matteo Dec 20 '14 at 02:17
  • The Java code is throwing an error - you can just see the end of a Java traceback in the 'before' field of the Pexpect error. You'll need to modify the corenlp Python code to show you the full traceback - something like this: http://pastebin.com/vqh5uGXF – Thomas K Dec 21 '14 at 20:23

0 Answers0