Day 5 of "a bug each weekday"

Yesterday I noticed Armin create issue 1164. Armin being who he is that meant the bug was about some edge case that most people wouldn't hit, but pointed out a fundamental issue with how something is handled in Python.

In this case it was the lack of GIL releasing when writing out to a 'FILE *' pointer (e.g., stdout). Turns out Armin found a way to trigger deadlock with the GIL by launching a thread to print out a long list while trying to read from stdin. This was because calls made to fprintf(), puts(), fputc() and fwrite() were being made while still holding the GIL when the 'print' statement was being called.

A quick patch with a bunch of Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS solved the problem. Waiting for a review of the patch before I try to go through every Python type and release the GIL as necessary.