Skip to content

Instantly share code, notes, and snippets.

@santiagobasulto
Created August 11, 2018 20:05
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 santiagobasulto/2bc51e7b0b0c7c2a74fd6d5748778dd7 to your computer and use it in GitHub Desktop.
Save santiagobasulto/2bc51e7b0b0c7c2a74fd6d5748778dd7 to your computer and use it in GitHub Desktop.
Pickle limitations for class based decorators.
from concurrent.futures import ProcessPoolExecutor
class CheckOnlyIntegers:
def __init__(self, fn):
self.fn = fn
def __call__(self, *args):
if not all([type(arg) == int for arg in args]):
raise ValueError("Invalid param is not an integer")
return self.fn(*args)
@CheckOnlyIntegers # this will change in the fixed version
def add(x, y):
return x + y
with ProcessPoolExecutor(max_workers=3) as ex:
futures = [
ex.submit(add, *(2, 3)),
ex.submit(add, *(9, 8)),
]
for future in futures:
print(future.result(timeout=3))
from concurrent.futures import ProcessPoolExecutor
class CheckOnlyIntegers:
def __init__(self, fn):
self.fn = fn
def __call__(self, *args):
if not all([type(arg) == int for arg in args]):
raise ValueError("Invalid param is not an integer")
return self.fn(*args)
def add(x, y):
return x + y
alternate_add = CheckOnlyIntegers(add) # Used instead of decorator
with ProcessPoolExecutor(max_workers=3) as ex:
futures = [
ex.submit(alternate_add, *(2, 3)),
ex.submit(alternate_add, *(9, 8)),
]
for future in futures:
print(future.result(timeout=3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment