title: How to create dynamically decorated (wrapped) functions that are pickable in python?
body: <p>Basically, how to make the second one work. The use case is to wrap function and trap exceptions/add timings etc.</p>
  
  <pre><code>import concurrent.futures
  import functools
  def with_print(func):
      """ Decorate a function to print its arguments.
      """
      @functools.wraps(func)
      def my_func(*args, **kwargs):
          print("LOOK", args, kwargs)
          return func(*args, **kwargs)
      return my_func
  
  def f():
      print('f called')
  
  g = with_print(f)
  
  executor = concurrent.futures.ProcessPoolExecutor(max_workers=10)
  
  tasks = [f for x in range(10)]
  fut = list()
  for task in tasks:
      fut.append(executor.submit(task))
  res = [x.result() for x in fut]
  print(res)
  
  
  # THIS ONE FAILS
  tasks = [g for x in range(10)]
  fut = list()
  for task in tasks:
      fut.append(executor.submit(task))
  res = [x.result() for x in fut]
  print(res)
  </code></pre>
  
  <p>Error is:</p>
  
  <p>_pickle.PicklingError: Can't pickle : it's not the same object as <strong>main</strong>.f</p>