title: Change decorator to implement in new module
body: <p>I have some class with a field <code>spent_times</code>. <code>spent_times</code> is a list and all methods of this class write some information, which is valuable for logging. </p>
  
  <p>Also, I have a decorator, which calculate execution time for every function and write it to <code>spent_times</code>. </p>
  
  <p>This is realization of my decorator:</p>
  
  <pre><code>def timing(message):
      def wrap(function):
          def called(*args, **kwargs):
              time_start = timer()
              spent_time = round(timer() - time_start, 5)
  
              if not args:
                  return function(*args, **kwargs), spent_time
  
              obj = args[0]
              if hasattr(obj, "spent_times"):
                  obj.spent_times.append("{}={:.5f}".format(message, spent_time))
                  return function(*args, **kwargs)
              else:
                  logging.warning('Decorator allows to set spent_time attribute!')
          return called
      return wrap 
  </code></pre>
  
  <p>As you can see in my decorator there is a check, if the calling function has attribute <em>self</em>. </p>
  
  <p>If it has, than I can write needed info in list <code>spent_times</code> on the spot, if it does not have, than decorator returns time spent on execution and function itself. </p>
  
  <p>I am using this decorator in one single module and second case (when no <em>self</em> found) belongs to some other functions in this module, which does not belong to class, where spent_time list is defined, but I execute them <strong>inside</strong> my class, so I am able to realize for example the following structure:</p>
  
  <p>This is declaration of "outer" function</p>
  
  <pre><code>def calc_users(requests, priority):
       # .....
  </code></pre>
  
  <p>And inside my class I execute it and update my spent_time list  this way:</p>
  
  <pre><code> response, spent_time = calc_users(requests, priority)
   self.class_obj.spent_times.append("user_calculation={:.5f}".format(spent_time))
  </code></pre>
  
  <p>which is not very nice, but it is working at least. </p>
  
  <p>Now,  I moved a few functions of my class in <strong>different</strong> new module and I would like to use the same decorator timing. </p>
  
  <p>Can someone help me to implement this realization of timing in new module. I do not know, what can I do to update my <code>spent_times</code> list now. </p>
  
  <p>These two modules will work at the same time and I cannot create object of class and pass it as an argument to new module, because (as far as I understand it) there will be two objects and spent_times will not be updated correctly. </p>
  
  <p>Maybe there is a way to pass a reference to <code>spent_times</code> somehow, but I do not want to change arguments of my functions in new module, since I think in this case principle of shared responsibility will be broken (decorator is responsible for logging, function for its action).</p>
  
  <p>So how to improve decorator or how to pass <code>spent_times</code> list to a new module?</p>
  
  <p>Any help will be greatly appreciate!</p>
  
  <p>P.S. </p>
  
  <p>Maybe make <code>spent_times</code> a global variable? (in the very worst case)</p>