Skip to content

Instantly share code, notes, and snippets.

@felipe-prenholato
Created April 13, 2012 03:36
Show Gist options
  • Save felipe-prenholato/2373455 to your computer and use it in GitHub Desktop.
Save felipe-prenholato/2373455 to your computer and use it in GitHub Desktop.
$ python teste.py
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 504, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/lib/python2.7/multiprocessing/pool.py", line 319, in _handle_tasks
put(task)
PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
^\Quit (core dumped)
$ python teste.py
990
991
992
993
994
995
996
997
998
[990, 991, 992, 993, 994, 995, 996, 997, 998]
(1, 990)
(2, 991)
(3, 992)
(4, 993)
(5, 994)
(6, 995)
(7, 996)
(8, 997)
(9, 998)
[(1, 990), (2, 991), (3, 992), (4, 993), (5, 994), (6, 995), (7, 996), (8, 997), (9, 998)]
(1, 990, 'foobar')
(2, 991, 'foobar')
(3, 992, 'foobar')
(4, 993, 'foobar')
(5, 994, 'foobar')
(6, 995, 'foobar')
(7, 996, 'foobar')
(8, 997, 'foobar')
(9, 998, 'foobar')
[(1, 990, 'foobar'), (2, 991, 'foobar'), (3, 992, 'foobar'), (4, 993, 'foobar'), (5, 994, 'foobar'), (6, 995, 'foobar'), (7, 996, 'foobar'), (8, 997, 'foobar'), (9, 998, 'foobar')]
# coding: utf-8
from multiprocessing import *
a = 'foobar'
def f(args):
print args
return args
def f2(args):
print args+(a,)
return args+(a,)
x = range(990,999)
p = Pool(2)
print p.map(f,x)
p = Pool(2)
print p.map(f,enumerate(x,1))
p = Pool(2)
print p.map(f2,enumerate(x,1))
# coding: utf-8
from multiprocessing import *
class T2:
def __init__(self):
a = 'foobar'
def f(args):
print args
return args
def f2(args):
print args+(a,)
return args+(a,)
x = range(990,999)
p = Pool(2)
print p.map(f,x)
p = Pool(2)
print p.map(f,enumerate(x,1))
p = Pool(2)
print p.map(f2,enumerate(x,1))
T2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment