Skip to content

Instantly share code, notes, and snippets.

@emakryo
Created January 1, 2018 13:36
Show Gist options
  • Save emakryo/9755647aed5a9f0c593ca530b2b9f769 to your computer and use it in GitHub Desktop.
Save emakryo/9755647aed5a9f0c593ca530b2b9f769 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%config Completer.use_jedi = False\n",
"import ipyparallel as ipp\n",
"import os, sys, socket"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0, 1, 2, 3, 4, 5, 6, 7]\n"
]
},
{
"data": {
"text/plain": [
"['b2', 'b11', 'b12', 'b6', 'b8', 'b13', 'b9', 'b15']"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# setup\n",
"c = ipp.Client()\n",
"print(c.ids)\n",
"dv = c[:]\n",
"dv.apply_sync(os.chdir, os.getcwd())\n",
"assert all([dir == os.getcwd() for dir in dv.apply_sync(os.getcwd)])\n",
"dv.apply_sync(socket.gethostname)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def f(x):\n",
" import time\n",
" time.sleep(20)\n",
" return x**2"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"ar = dv.map_async(f, range(16))"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 8/8 tasks finished after 60 s\n",
"done\n"
]
}
],
"source": [
"ar.wait_interactive()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ar.ready()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "parallel",
"language": "python",
"name": "parallel"
},
"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.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment