{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Holding the GIL for too long could disrupt the heartbeat due to non-copying sends.\n", "\n", "The following cell repeatedly calls a function that holds the GIL for five seconds.\n", "\n", "The heartbeat will fail after a few iterations prior to fixing Issue [#1260](https://github.com/ipython/ipython/issues/1260)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import sys\n", "import time\n", "\n", "from cython import inline\n", "\n", "def gilsleep(t):\n", " \"\"\"gil-holding sleep with cython.inline\"\"\"\n", " code = '\\n'.join([\n", " 'from posix cimport unistd',\n", " 'unistd.sleep(t)',\n", " ])\n", " while True:\n", " inline(code, quiet=True, t=t)\n", " print time.time()\n", " sys.stdout.flush() # this is important\n", "\n", "gilsleep(5)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.2" } }, "nbformat": 4, "nbformat_minor": 0 }