Skip to content

Instantly share code, notes, and snippets.

@holdenweb
Created January 18, 2013 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holdenweb/4562840 to your computer and use it in GitHub Desktop.
Save holdenweb/4562840 to your computer and use it in GitHub Desktop.
Some code it isn't reasonable to expect to run in a notebook?
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "SneakyThreading"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"import threading\n",
"import time\n",
"\n",
"class counterThread(threading.Thread):\n",
" def run(self):\n",
" for i in range(5):\n",
" time.sleep(2)\n",
" print i"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"for i in (1, 2, 3):\n",
" counterThread().start()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"4\n",
"4\n"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"0\n",
"0\n",
"0\n",
"1"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"1\n",
"1\n",
"2"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"2\n",
"2\n",
"3"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"3\n",
"3\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment