diff --git a/examples/lib/BackgroundJobs.ipynb b/examples/lib/BackgroundJobs.ipynb index 595886d..89afacb 100644 --- a/examples/lib/BackgroundJobs.ipynb +++ b/examples/lib/BackgroundJobs.ipynb @@ -1,6 +1,6 @@ { "metadata": { - "name": "BackgroundJobs" + "name": "" }, "nbformat": 3, "nbformat_minor": 0, @@ -20,6 +20,7 @@ "cell_type": "code", "collapsed": false, "input": [ + "from __future__ import print_function\n", "from IPython.lib import backgroundjobs as bg\n", "\n", "import sys\n", @@ -39,15 +40,15 @@ "def printfunc(interval=1, reps=5):\n", " for n in range(reps):\n", " time.sleep(interval)\n", - " print 'In the background...', n\n", + " print('In the background...', n)\n", " sys.stdout.flush()\n", - " print 'All done!'\n", + " print('All done!')\n", " sys.stdout.flush()" ], "language": "python", "metadata": {}, "outputs": [], - "prompt_number": 35 + "prompt_number": 1 }, { "cell_type": "markdown", @@ -87,37 +88,9 @@ "Starting job # 4 in a separate thread.\n", "Starting job # 5 in a separate thread.\n" ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "In the background... 0\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "In the background... 1\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "In the background... 2\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "All done!\n" - ] } ], - "prompt_number": 36 + "prompt_number": 2 }, { "cell_type": "markdown", @@ -139,19 +112,27 @@ "output_type": "stream", "stream": "stdout", "text": [ - "Completed jobs:\n", - "0 : <function sleepfunc at 0x30e1578>\n", - "2 : <function sleepfunc at 0x30e1578>\n", + "In the background... 0\n", + "Running jobs:" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "0 : \n", + "2 : \n", "3 : printfunc(1,3)\n", + "5 : \n", "\n", "Dead jobs:\n", - "4 : <function diefunc at 0x304d488>\n", - "5 : <function diefunc at 0x304d488>\n", + "4 : \n", "\n" ] } ], - "prompt_number": 37 + "prompt_number": 3 }, { "cell_type": "markdown", @@ -170,8 +151,18 @@ ], "language": "python", "metadata": {}, - "outputs": [], - "prompt_number": 43 + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "In the background... 1\n", + "In the background... 2\n", + "All done!\n" + ] + } + ], + "prompt_number": 4 }, { "cell_type": "markdown", @@ -193,29 +184,15 @@ "metadata": {}, "outputs": [ { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Status of diejob1: Dead (Exception), call jobs.traceback() for details\n", - "---------------------------------------------------------------------------\n", - "Exception Traceback (most recent call last)\n", - "/home/fperez/usr/lib/python2.6/site-packages/IPython/lib/backgroundjobs.py in call(self)\n", - " 462 \n", - " 463 def call(self):\n", - "--> 464 return self.func(*self.args, **self.kwargs)\n", - "\n", - "/home/fperez/ipython/ipython/docs/examples/lib/<ipython-input-15-54795a097787> in diefunc(interval, *a, **kw)\n", - " 14 def diefunc(interval=2, *a, **kw):\n", - " 15 time.sleep(interval)\n", - "---> 16 raise Exception("Dead job with interval %s" % interval)\n", - " 17 \n", - " 18 def printfunc(interval=1, reps=5):\n", - "\n", - "Exception: Dead job with interval 1\n" + "ename": "SyntaxError", + "evalue": "invalid syntax (, line 1)", + "output_type": "pyerr", + "traceback": [ + "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m print \"Status of diejob1:\", diejob1.status\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" ] } ], - "prompt_number": 34 + "prompt_number": 5 }, { "cell_type": "markdown", @@ -237,44 +214,44 @@ "output_type": "stream", "stream": "stdout", "text": [ - "Traceback for: <BackgroundJob #4: <function diefunc at 0x30df758>>\n", - "---------------------------------------------------------------------------\n", - "Exception Traceback (most recent call last)\n", - "/home/fperez/usr/lib/python2.6/site-packages/IPython/lib/backgroundjobs.py in call(self)\n", - " 462 \n", - " 463 def call(self):\n", - "--> 464 return self.func(*self.args, **self.kwargs)\n", + "Traceback for: >\n", + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n", + "\u001b[1;31mException\u001b[0m Traceback (most recent call last)\n", + "\u001b[1;32m/home/takluyver/.local/lib/python3.3/site-packages/IPython/lib/backgroundjobs.py\u001b[0m in \u001b[0;36mcall\u001b[1;34m(self)\u001b[0m\n", + "\u001b[0;32m 489\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0;32m 490\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mcall\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m--> 491\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0m\n", + "\u001b[1;32m\u001b[0m in \u001b[0;36mdiefunc\u001b[1;34m(interval, *a, **kw)\u001b[0m\n", + "\u001b[0;32m 14\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mdiefunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minterval\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkw\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0;32m 15\u001b[0m \u001b[0mtime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minterval\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m---> 16\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mException\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Dead job with interval %s\"\u001b[0m \u001b[1;33m%\u001b[0m \u001b[0minterval\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0m\u001b[0;32m 17\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0;32m 18\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mprintfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minterval\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mreps\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\n", - "/home/fperez/ipython/ipython/docs/examples/lib/<ipython-input-15-54795a097787> in diefunc(interval, *a, **kw)\n", - " 14 def diefunc(interval=2, *a, **kw):\n", - " 15 time.sleep(interval)\n", - "---> 16 raise Exception("Dead job with interval %s" % interval)\n", - " 17 \n", - " 18 def printfunc(interval=1, reps=5):\n", + "\u001b[1;31mException\u001b[0m: Dead job with interval 1\n", "\n", - "Exception: Dead job with interval 1\n", + "Traceback for: >\n", + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n", + "\u001b[1;31mException\u001b[0m Traceback (most recent call last)\n", + "\u001b[1;32m/home/takluyver/.local/lib/python3.3/site-packages/IPython/lib/backgroundjobs.py\u001b[0m in \u001b[0;36mcall\u001b[1;34m(self)\u001b[0m\n", + "\u001b[0;32m 489\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0;32m 490\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mcall\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m--> 491\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0m\n", + "\u001b[1;32m\u001b[0m in \u001b[0;36mdiefunc\u001b[1;34m(interval, *a, **kw)\u001b[0m\n", + "\u001b[0;32m 14\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mdiefunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minterval\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkw\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0;32m 15\u001b[0m \u001b[0mtime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minterval\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m---> 16\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mException\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Dead job with interval %s\"\u001b[0m \u001b[1;33m%\u001b[0m \u001b[0minterval\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0m\u001b[0;32m 17\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[0;32m 18\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mprintfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minterval\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mreps\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\n", - "Traceback for: <BackgroundJob #5: <function diefunc at 0x30df758>>\n", - "---------------------------------------------------------------------------\n", - "Exception Traceback (most recent call last)\n", - "/home/fperez/usr/lib/python2.6/site-packages/IPython/lib/backgroundjobs.py in call(self)\n", - " 462 \n", - " 463 def call(self):\n", - "--> 464 return self.func(*self.args, **self.kwargs)\n", - "\n", - "/home/fperez/ipython/ipython/docs/examples/lib/<ipython-input-15-54795a097787> in diefunc(interval, *a, **kw)\n", - " 14 def diefunc(interval=2, *a, **kw):\n", - " 15 time.sleep(interval)\n", - "---> 16 raise Exception("Dead job with interval %s" % interval)\n", - " 17 \n", - " 18 def printfunc(interval=1, reps=5):\n", - "\n", - "Exception: Dead job with interval 2\n", + "\u001b[1;31mException\u001b[0m: Dead job with interval 2\n", "\n" ] } ], - "prompt_number": 33 + "prompt_number": 6 }, { "cell_type": "markdown", @@ -296,11 +273,12 @@ "output_type": "stream", "stream": "stdout", "text": [ - "No jobs to flush.\n" + "Flushing 3 Completed jobs.\n", + "Flushing 2 Dead jobs.\n" ] } ], - "prompt_number": 25 + "prompt_number": 7 }, { "cell_type": "markdown", @@ -318,7 +296,7 @@ "language": "python", "metadata": {}, "outputs": [], - "prompt_number": 27 + "prompt_number": 8 }, { "cell_type": "markdown", @@ -332,10 +310,10 @@ "collapsed": false, "input": [ "j = jobs.new(sleepfunc, 2)\n", - "print \"Will wait for j now...\"\n", + "print(\"Will wait for j now...\")\n", "sys.stdout.flush()\n", "j.join()\n", - "print \"Result from j:\"\n", + "print(\"Result from j:\")\n", "j.result" ], "language": "python", @@ -345,7 +323,7 @@ "output_type": "stream", "stream": "stdout", "text": [ - "Starting job # 7 in a separate thread.\n", + "Starting job # 0 in a separate thread.\n", "Will wait for j now...\n" ] }, @@ -357,14 +335,15 @@ ] }, { + "metadata": {}, "output_type": "pyout", - "prompt_number": 46, + "prompt_number": 9, "text": [ - "{'args': (), 'interval': 2, 'kwargs': {}}" + "{'kwargs': {}, 'args': (), 'interval': 2}" ] } ], - "prompt_number": 46 + "prompt_number": 9 }, { "cell_type": "code",