Skip to content

PtyProcess.spawn (and thus pexpect) is not safe for use in multithreaded applications #43

@gpshead

Description

@gpshead

Just the same as the old pure Python subprocess module from Python 2, the PtyProcess.spawn method is not async signal safe. The entire fork() to exec code path must be written in async signal safe C code. Both pty.fork and your own PtyProcess.spawn method violate this constraint.

See the Python 3 subprocess module's _posixsubprocess extension module (and the https://pypi.python.org/pypi/subprocess32/ backport for Python 2 users).

Likely symptoms when this bites you: random seeming deadlocks and hangs.

Workaround for users today: Do not use pexpect.spawn or pexpect.pty_spawn in a multithreaded application.
A pexpect.popen_spawn module appears to exist and will use the subprocess module. If you are on 2.7 make sure you've replaced sys.modules['subprocess'] with a reference to the subprocess32 module first (if you haven't already done so within your Python 2.7 interpreter's stdlib)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions