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

Py30a3: eval in threaded code raises SystemError #46474

Closed
mark-summerfield mannequin opened this issue Mar 3, 2008 · 7 comments
Closed

Py30a3: eval in threaded code raises SystemError #46474

mark-summerfield mannequin opened this issue Mar 3, 2008 · 7 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@mark-summerfield
Copy link
Mannequin

mark-summerfield mannequin commented Mar 3, 2008

BPO 2221
Nosy @gvanrossum, @kbkaiser, @amauryfa, @mark-summerfield

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2008-04-04.23:26:32.285>
created_at = <Date 2008-03-03.11:34:29.007>
labels = ['interpreter-core']
title = 'Py30a3: eval in threaded code raises SystemError'
updated_at = <Date 2008-04-10.20:58:39.366>
user = 'https://github.com/mark-summerfield'

bugs.python.org fields:

activity = <Date 2008-04-10.20:58:39.366>
actor = 'amaury.forgeotdarc'
assignee = 'none'
closed = True
closed_date = <Date 2008-04-04.23:26:32.285>
closer = 'amaury.forgeotdarc'
components = ['Interpreter Core']
creation = <Date 2008-03-03.11:34:29.007>
creator = 'mark'
dependencies = []
files = []
hgrepos = []
issue_num = 2221
keywords = []
message_count = 7.0
messages = ['63209', '64935', '64952', '64953', '64956', '65258', '65319']
nosy_count = 4.0
nosy_names = ['gvanrossum', 'kbk', 'amaury.forgeotdarc', 'mark']
pr_nums = []
priority = 'high'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue2221'
versions = ['Python 3.0']

@mark-summerfield
Copy link
Mannequin Author

mark-summerfield mannequin commented Mar 3, 2008

In IDLE for Py30a3 if you enter:

>> class A(

as soon as you type the ( you get the following output to stderr (on
Fedora 8 with Tcl/Tk 8.4):

: *** Internal Error: rpc.py:SocketIO.localcall()

Object: exec
Method: <bound method Executive.get_the_calltip of
<idlelib.run.Executive object at 0xb70f2b4c>>
Args: ('A',)

Traceback (most recent call last):
  File "/home/mark/opt/python30a3/lib/python3.0/idlelib/rpc.py", line
188, in localcall
    ret = method(*args, **kwargs)
  File "/home/mark/opt/python30a3/lib/python3.0/idlelib/run.py", line
316, in get_the_calltip
    return self.calltip.fetch_tip(name)
  File "/home/mark/opt/python30a3/lib/python3.0/idlelib/CallTips.py",
line 103, in fetch_tip
    entity = self.get_entity(name)
  File "/home/mark/opt/python30a3/lib/python3.0/idlelib/CallTips.py",
line 112, in get_entity
    return eval(name, namespace)
SystemError: error return without exception set

It does not appear to affect IDLE's functionality.

@kbkaiser
Copy link
Contributor

kbkaiser commented Apr 4, 2008

I don't think that this is an IDLE error. It
can be more generally exhibited as follows:

Without the subprocess we get the expected:

IDLE 3.0a4 ==== No Subprocess ====

>>> eval('a')
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    eval('a')
  File "<string>", line 1, in <module>
NameError: name 'a' is not defined

With the subprocess there is an interpreter
error when IDLE applies eval to 'a':

IDLE 3.0a4      
>>> eval('a')
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    eval('a')
SystemError: error return without exception set

I did a cutdown where I ran the eval in a
subprocess and didn't reproduce the error. I
suspect it's thread related (the subprocess
uses its main thread to execute user code, and
another thread to manage the socket connection
to the GUI process).

bpo-1733757 is suggestive.

This is a 3.0 issue, it doesn't occur in the
trunk.

@kbkaiser kbkaiser added interpreter-core (Objects, Python, Grammar, and Parser dirs) and removed topic-IDLE labels Apr 4, 2008
@kbkaiser kbkaiser changed the title Py30a3: calltip produces error output to stderr Py30a3: eval in threaded code raises SystemError Apr 4, 2008
@kbkaiser kbkaiser removed their assignment Apr 4, 2008
@amauryfa
Copy link
Member

amauryfa commented Apr 4, 2008

The problem is just that in Python/pythonrun.c, the function run_mod()
calls flush_io() after executing the code. In our testcase, there is a
pending exception.
But flush_io() silently ignore errors (which is fine), and clears all
exception info (which is bad).
To correct the problem, I it is enough to calls to
PyErr_Fetch/PyErr_Restore.

This happens only with Idle, probably because the subprocess redirected
its stdout to a pseudo-file that does not support flush().

@amauryfa
Copy link
Member

amauryfa commented Apr 4, 2008

Committed r62157.

Will also investigate why exec() needs to flush sys.stdout...

@amauryfa amauryfa closed this as completed Apr 4, 2008
@kbkaiser
Copy link
Contributor

kbkaiser commented Apr 5, 2008

Thanks, that does appear to fix the IDLE problem!

The pseudofile does have a flush method and I was able to
call it from the IDLE subprocess; it returns None. So I'm
not clear on why PyObject_CallMethod was returning False, or
why the problem only occurred when IDLE was running its subprocess.

@kbkaiser
Copy link
Contributor

kbkaiser commented Apr 9, 2008

PyObject_CallMethod is actually returning a
non-NULL result for sys.std{out,err}, and
PyErr_Clear() isn't being run in flush_io.

The problem is deeper. PyErr is being
used during unexceptional processing in
typeobject.c:slot_tp_getattr_hook() to
indicate that PyObject_GenericGetAttr() failed
and the __getattr__ method (used in IDLE)
should be called.

Perhaps PyErr should be preserved in
slot_tp_getattr_hook(), instead. Is this
possibly a potential 2.6 issue for some uses
of getattr? Or is the current solution 'good
enough'?

ref bpo-1400.

@amauryfa
Copy link
Member

I think this is good enough: you should not invoke python code with a
pending exception set (PyErr_Occurred()).

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)
Projects
None yet
Development

No branches or pull requests

2 participants