Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Teijo Holzer: Fixing Python

Teijo Holzer: Fixing Python

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Teijo Holzer:
Fixing Python
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
@ Kiwi PyCon 2014 - Saturday, 13 Sep 2014 - Track 2
http://kiwi.pycon.org/

**Audience level**

Intermediate

**Description**

Discover a bug in a standard Python library, provide a reproducible test case, log a bug report with the Python maintainers, prepare & submit a patch. Get patch accepted into 2.x & 3.x master.

**Abstract**

This talk will provide a real-world walk-through of how to discover a bug in Python, prepare a reproducible test case and log a bug report. It will then continue to show on how to provide a patch and get it accepted and deployed into Python 2.7.7 and 3.4.1

**YouTube**

https://www.youtube.com/watch?v=i7EZAfhIvCs

6b880a0b67fac54c42c77fe70d97334d?s=128

New Zealand Python User Group

September 13, 2014
Tweet

Transcript

  1. Fixing Python  Teijo Holzer  Production Engineer  Weta

    Digital  Python for 7 years
  2. Every Program has Bugs print 'Hello World'

  3. Every Program has Bugs while 1: print 'Hello World'

  4. Hello World Fail #1 $ python test.py | head ­n

    1 Hello World Traceback (most recent call last): File "test.py", line 2, in <module> print 'Hello World' IOError: [Errno 32] Broken pipe
  5. Hello World Fail #2 $ python test.py > /dev/tcp/localhost/22 Traceback

    (most recent call last): File "test.py", line 2, in <module> print 'Hello World' IOError: [Errno 104] Connection reset by peer
  6. Hello World Fail #3 $ python test.py >&­ Traceback (most

    recent call last): File "test.py", line 2, in <module> print 'Hello World' IOError: [Errno 9] Bad file descriptor
  7. Fixing the Standard Library  tempfile.NamedTemporaryFile  Creates a temporary

    file  Takes 'mode' argument  Invalid mode argument triggers bug  Bug is a file descriptor leak
  8. Test Case import tempfile while 1: try: tempfile.NamedTemporaryFile(mode='x') except ValueError:

    pass # OSError: [Errno 24] Too many open files
  9. Patch # Lib/tempfile.py ­ file = _os.fdopen(fd, mode, bufsize) +

    try: + file = _os.fdopen(fd, mode, bufsize) + except Exception as ex: + _os.close(fd) + raise
  10. Submit Bug, Test Case & Patch  http://bugs.python.org/  Sign

    up  Search for existing bug reports  Submit bug report, test case & patch (if available)  Wait for reply & adaption into main branches
  11. Summary  Every program has bugs  Fixing Python is

    possible  Help out by improving Python  Always provide reproducible test case  tempfile patch (Issue 21058) is in 2.7.8 & 3.4.1