Skip to content

Python 2.x 3.x compatibility notes

Alex Willmer edited this page Dec 9, 2025 · 6 revisions

Exceptions

Exception hierachy

Python <= 3.2

  • BaseException
    • Exception
      • StandardError
        • EnvironmentError
          • IOError
            • socket.error
          • OSError
      • select.error

Python >= 3.3

  • BaseException
    • Exception
      • OSError
        • BlockingIOError
        • EnvironmentError
        • IOError
        • select.error
        • socket.error

Refs

InterruptedError

Python 3.5+ automatically retries system calls that return EINTR.

Backports

Files

  • open(), os.fdopen(), etc return
    • file instances in Python 2.x
    • io.* instances in Python 3.x
  • io module requires Python >= 2.6
  • BlockingIOError requires Python >= 3.3 (first doc mention Python 3.4)

Non-blocking behaviour

In non-blocking mode, if n > 0 is specified, and no bytes are available

subprocess

  • Python >= 2.4
  • Python >= 2.6: Popen.send_signal(s), Popen.terminate(), Popen.kill()
  • Python >= 3.3: Popen.communicate(..., timeout)

Clone this wiki locally