Skip to content

'import readline' hangs when launching with '&' on BSD and OS X #59097

Closed

Description

@olivier-mattelaer
BPO 14892
Nosy @ronaldoussoren, @ned-deily

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 = 'https://github.com/ronaldoussoren'
closed_at = <Date 2012-11-30.14:24:18.742>
created_at = <Date 2012-05-23.18:55:18.815>
labels = ['type-bug', 'invalid']
title = "'import readline' hangs when launching with '&' on BSD and OS X"
updated_at = <Date 2012-11-30.14:24:18.741>
user = 'https://bugs.python.org/olivier-mattelaer'

bugs.python.org fields:

activity = <Date 2012-11-30.14:24:18.741>
actor = 'ronaldoussoren'
assignee = 'ronaldoussoren'
closed = True
closed_date = <Date 2012-11-30.14:24:18.742>
closer = 'ronaldoussoren'
components = []
creation = <Date 2012-05-23.18:55:18.815>
creator = 'olivier-mattelaer'
dependencies = []
files = []
hgrepos = []
issue_num = 14892
keywords = []
message_count = 4.0
messages = ['161450', '161465', '173501', '173541']
nosy_count = 3.0
nosy_names = ['ronaldoussoren', 'ned.deily', 'olivier-mattelaer']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue14892'
versions = ['Python 2.7', 'Python 3.2', 'Python 3.3']

Activity

  1. olivier-mattelaer commented on May 23, 2012

    olivier-mattelaermannequin
    MannequinAuthor

    Hi Everyone,

    I have found a strange behavior of the import command for the routine readline:

    The commands (put in the file test.py) is simply:
    import readline
    print readline.__doc__

    If I run this programs "normally" (i.e. python2.x test.py) everything runs normally:
    [tmp]$ python2.7 tmp.py
    Importing this module enables command line editing using GNU readline.

    But if I launched it in the following way:
    python2.X test.py &
    It's stops before finishing the import command (so no output even if I print the output into a file).
    This doesn't raise any error just stop the program.

    I tried to add a try...except...finally... but even the finally statement is not executed.

    Of course, I realize that readline is not that interesting to load with that options. So I would be more than happy if you could indicate me a way to either detect that the user launch the program with '&' or a way to avoid readline to stop the program in this situations.

    Thanks a lot,

    Olivier

  2. added
    type-crash
    on May 23, 2012
  3. ned-deily commented on May 23, 2012

    @ned-deily
    Member

    I took a quick look at this. It's not just OS X, the following also fails on FreeBSD 8.2:

    $ python2.7 -c 'import readline'
    $ 
    $ python2.7 -c 'import readline' &
    $ 
    [1] + Stopped (tty output)    python2.7 -c ?import readline

    It seems to be hanging on a read from stdin, as adding a redirect of stdin to /dev/null prevents the hang:

    $ python2.7 -c 'import readline' </dev/null &
    [1] 36178
    $ 
    [1]+  Done                    python2.7 -c 'import readline' < /dev/null

    But, on Debian and Ubuntu, neither case hangs. Also, on OS X, the same hang behavior is observed when linked with either GNU readline or BSD libedit. I'm not sure what the significant difference here is: possibly a BSDism vs Linuxism?

  4. changed the title [-]'import readline' fails when launching with '&'[/-] [+]'import readline' hangs when launching with '&' on BSD and OS X[/+] on May 23, 2012
  5. added
    type-bug
    and removed
    type-crash
    on May 23, 2012
  6. ronaldoussoren commented on Oct 22, 2012

    @ronaldoussoren
    Contributor

    I've just tested this on OSX 10.8.2 and the problem is not present there (that is, 'python -c "import deadline" &' does not hang)

    The problem is present on OSX 10.6.8, and when using ksh(1) you can see why the process is stopped:

    [1] + Stopped(SIGTTOU) python -c 'import readline' &

    That signal is generated when the program generates output to a tty and the TOSTOP option of stty is active. Whether or not that option is active is OS configuration (and can be changed using the stty command).

    Reading the option:

    import termios
    lflags = termios.tcgetattr(0)[3]
    print (lflags & termios.TOSTOP) != 0

    Oddly enough the option off on both OSX 10.6 and 10.8, which point to a bug in OSX 10.6 (or to a misunderstanding of low-level tty programming details on my part which would not be unlikely)

    Anyway, there is an easy workaround: before importing readline add:

    import signal
    signal.signal(signal.SIGTTOU, signal.SIG_IGN)

    This ignores the SIGTTOU option and allows me to import readline on the background.

    IMHO This issue can be closed because this behavior is not a Python bug but a platform feature.

  7. olivier-mattelaer commented on Oct 22, 2012

    olivier-mattelaermannequin
    MannequinAuthor

    Thanks a lot Ronald.

    Cheers,

    Olivier

  8. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

type-bug

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions