This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dirty_ls = list(l) | |
dirty_ls[600], dirty_ls[20000] = ("kittens","cats") | |
res = map(add_one2,dirty_ls) | |
# ***Repl Closed*** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EmbeddedFunctionHandler.init_log('file.log', logging.DEBUG) | |
MAX_ERRORS = 2 | |
@EmbeddedFunctionHandler("catch errors adding 1", MAX_ERRORS) | |
def add_one2(x): | |
return x+1 | |
%timeit map(add_one2,l) | |
# 1 loops, best of 3: 1.13 s per loop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from multiprocessing import Pool | |
def add_one(x): | |
return x+1 | |
p = Pool(4) | |
l = np.arange(0,1000000) | |
%timeit p.map(add_one, l) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
EmbeddedFunctionHandler.py | |
A class that decorates functions that are embedded/called within | |
other map|reduce functions. Provides error logging | |
to log. Type of error and function *args are logged. Useful for Python's | |
dynamic typing | |
""" |
NewerOlder