Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python shell handling is broken. #3

Open
linas opened this issue Jul 27, 2016 · 4 comments
Open

python shell handling is broken. #3

linas opened this issue Jul 27, 2016 · 4 comments

Comments

@linas
Copy link
Member

linas commented Jul 27, 2016

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.

@linas
Copy link
Member Author

linas commented Jul 27, 2016

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

@ngeiswei
Copy link
Member

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.

@smigad
Copy link
Member

smigad commented Aug 30, 2016

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

linas referenced this issue in opencog/opencog Nov 8, 2016
Re-enable the test after #2322 is fixed.
@linas
Copy link
Member Author

linas commented Nov 8, 2016

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.

@linas linas transferred this issue from opencog/opencog Sep 14, 2019
linas pushed a commit that referenced this issue Jul 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants