opencog / cogserver

Distributed AtomSpace Network Server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

python shell handling is broken.

linas opened this issue · comments

See comments in pull request opencog/atomspace#838

At this time, starting the cogserver, and then telnet localhost 17001, entering the python shell, and entering this:

for i in range(10) :
    print "foo", i

produces no output in either the shell or the cogserver (see also issue #2 -- currently prints go to the cogserver; once fixed, prints should go to the shell.) There are also various inconsistencies: running the python shell stand-alone gives this:

$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> 
>>> 
>>> 

after hitting carriage return 3 times. Doing the same in the telnet terminal gives this:

$ telnet localhost 17001
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
opencog> py
Entering python shell; use ^D or a single . on a line by itself to exit.
py> 
... 
... 
py> 
py> 
... 
... 
... 
... 
... 
... 
py> 
... 
... 
... 
... 
py> 
... 

There are also inconsistencies in what python considers to be "legal syntax". For example, the following code, when entered at the python shell, is invalid syntax:

def fun(x):
    y = x + 1

    print "foo", y
    return y

fun(1)
print "bar"

it generates this error:

$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def fun(x):
...     y = x + 1
... 
>>>     print "foo", y
  File "<stdin>", line 1
    print "foo", y
    ^
IndentationError: unexpected indent
>>> 

however, copying that code to a file, say f.py and running it as $ python f.py does not produce any error:

$ python f.py
foo 2
bar
$

running the above code at the telnet prompt does nothing.

I'm not sure quite how to resolve this ... if python itself is not self-consistent with what it considers to be valid syntax, I'm not sure how how to emulate that .. at any rate, the telnet shell is clearly broken.

One reason the telnet shell is broken is that we have no unit tests for it. Once upon a time, it used to work.

python results are discarded so it's difficult to test it. Agreed it is broken, but I guess we'll address that more deeply after the demo.

I sort of got it working
Code like this works fine

for i in range(10) :
    print "foo", i

but code like the one u posted with the empty line inside a scope doesn't work
because like the standard interpreter, an empty line ends a scope(when typed in).
https://github.com/Dagiopia/atomspace/blob/master/opencog/cython/PythonEval.cc

I stubbed out line 107 of tests/cython/PythonModuleUTest.cxxtest until this issue is resolved. When this bug is fixed, then that line should be enabled again.