[ python-Bugs-1166660 ] The readline module can cause python to segfault

SourceForge.net noreply at sourceforge.net
Wed Mar 30 13:23:54 CEST 2005


Bugs item #1166660, was opened at 2005-03-19 21:48
Message generated for change (Comment added) made by mwh
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1166660&group_id=5470

Category: Threads
Group: Platform-specific
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Yariv Ido (dcoder)
Assigned to: Michael Hudson (mwh)
Summary: The readline module can cause python to segfault

Initial Comment:
When starting an interactive interpreter in another
thread, with readline's completion functionality, there
exists a race condition which causes the Python
interpreter to segfault. There's a small discussion
about this bug at
<http://www.scipy.net/roundup/ipython/issue30>.

Attached is a small proof-of-concept code. Please note
that some people couldn't reproduce this on slower
machines. I've managed to reproduce it on several Linux
systems (Dual Xeon computers), using Python 2.3.4, 2.4
and 2.4.1c2.

Thanks in advance.

----------------------------------------------------------------------

>Comment By: Michael Hudson (mwh)
Date: 2005-03-30 12:23

Message:
Logged In: YES 
user_id=6656

Oh, forget all that, I had a leap in understanding about the existing threads-
vs-hooks code in readline.c: it's all insane nonsense.

I used the PyGILState_* API rather than your suggestion, on the very faint 
chance that an embedder might be calling readline() directly and thus have 
not be setting _PyOS_ReadlineTState.

I also fixed the 'checking the return value from a hook function' while I was 
there, so you don't need to submit a new report for that.

Modules/readline.c revision 2.83.

Thanks for the report!


----------------------------------------------------------------------

Comment By: Michael Hudson (mwh)
Date: 2005-03-30 11:10

Message:
Logged In: YES 
user_id=6656

While it does seem a bit odd to call the completer function in the thread 
that calls set_completer and not the thread that calls readline(), I don't 
immediately see how this is leading to segfaults.  Do you?

Anyway, I can reproduce the problem, so if your fix fixes it, I'll check it in 
(irrespective of fixing segfaults, it just makes more sense).

----------------------------------------------------------------------

Comment By: Michael Hudson (mwh)
Date: 2005-03-29 13:10

Message:
Logged In: YES 
user_id=6656

Unless there's some reason to suspect they share a common
cause (and, I don't see one) a second report is more
appropriate.

Also, if you understand what's going on, you can explain
there :)

----------------------------------------------------------------------

Comment By: Yariv Ido (dcoder)
Date: 2005-03-28 23:33

Message:
Logged In: YES 
user_id=326689

I haven't (Completely forgot about it, after finding the
main one...). Should I post a seperate bug report, or will
this one do?

----------------------------------------------------------------------

Comment By: Michael Hudson (mwh)
Date: 2005-03-27 21:43

Message:
Logged In: YES 
user_id=6656

I'll take a look at this.

Did you submit a bug on the set_startup_hook problem mentioned in the 
ipython tracker?

----------------------------------------------------------------------

Comment By: Yariv Ido (dcoder)
Date: 2005-03-19 23:59

Message:
Logged In: YES 
user_id=326689

I may be completely off track here, but shouldn't
on_completion(...) (readline.c) use _PyOS_ReadlineTState
instead of completer_tstate to restore the GIL?

Also, in readline_until_enter_or_signal(...), shouldn't
PyEval_SaveThread()'s return value be saved back to 
_PyOS_ReadlineTState?

It seems that these patches manage to fix the above
segmentation fault...

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1166660&group_id=5470


More information about the Python-bugs-list mailing list