Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6122321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:53:06+00:00 2026-05-23T15:53:06+00:00

We use a library provided by another internal team. (Shaky analogy starts now) from

  • 0

We use a library provided by another internal team. (Shaky analogy starts now)

from externalTeam import dataCreator
datacreator.createPizza()
datacreator.createBurger()
datacreator.createHotDog()

Recently we found a single method of theirs was taking over a minute to execute in certain situations. To debug this, I had to go into our code and add timeouts around every call of this method.

import time
from externalTeam import dataCreator
start = time.clock()
datacreator.createPizza()
stop = time.clock()
print "It took %s seconds to perform createPizza" % (str(stop-start))

In hindsight, that’s because we’re calling createPizza all over the place, and we don’t control createPizza itself (the analogy is starting to break down a little here). I’d rather just call createPizza in one place, and be able to add a timer around that. My first thought to accomplish this would be to create a wrap all their methods in my own wrapper class. That’s the opposite of DRY though, and anytime they add another method I’d have to update our library to wrap that as well:

import time
from externalTeam import dataCreator
def createPizza(self):
    start = time.clock()
    datacreator.createPizza()
    stop = time.clock()
    print "It took %s seconds to perform createPizza" % (str(stop-start))

def createBurger(self):
    start = time.clock()
    datacreator.createPizza()
    stop = time.clock()
    print "It took %s seconds to perform createBurger" % (str(stop-start))

def createHotDog(self):
    start = time.clock()
    datacreator.createPizza()
    stop = time.clock()
    print "It took %s seconds to perform createHotDog" % (str(stop-start))    

What I want is a way to always execute a few lines of code around every function that’s being called from dataCreator. There must be some way to do that through an intermediate class whose methods can be dynamically defined – or rather left undefined, right?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:53:07+00:00Added an answer on May 23, 2026 at 3:53 pm

    I would create a dataCreator adapter class that would work like this:

    1. Have a methods2wrap list of the methods from dataCreator that needs to be wrapped into the debugging/timing functionality.
    2. Have an overridden __getattribute__() that would map 1:1 onto the dataCreator methods, wrapping the methods in methods2wrap into a timing debug message.

    Proof-of-concept code (the example wrap the class list and insert a debugging timestamp around its method append).

    import time
    
    class wrapper(list):
    
        def __getattribute__(self, name):
            TO_OVERRIDE = ['append']
            if name in TO_OVERRIDE:
                start = time.clock()
            ret = super(list, self).__getattribute__(name)
            if name in TO_OVERRIDE:
                stop = time.clock()
                print "It took %s seconds to perform %s" % (str(stop-start), name)
            return ret
    
    profiled_list = wrapper('abc')
    print profiled_list
    profiled_list.append('d')
    print profiled_list
    profiled_list.pop()
    print profiled_list
    

    Of course you could build on this example and make it parametric, so that at initialisation time you can set what class to wrap and what methods should be timed…

    EDIT: Note that TO_OVERRIDE is reassigned at each __getattribute__ call. This is by design. If you you would make it as a class attribute, __getattribute__ would recursively loop (you should use an explicit call to the parent __getattribute__ method to retrieve it, but this would probably be slower than simply rebuild the list from scratch.

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Another guy on our team has provided me a library as a jar for
I use SharpSvn library from CollabNET. I would like to set revision author while
I use this library: https://github.com/robbiehanson/CocoaAsyncSocket My test code: #import <UIKit/UIKit.h> @class GCDAsyncUdpSocket; @interface ThirdViewController
I've got a library defined by another team. It has something like the following:
I use UIDatePicker component from iOS 5.1 library for selecting datetime value which is
We use Enterprise Library 3.0 to access Oracle DB (microsoft oracle client). What happens
How can I use Enterprise Library to do a Data Access Layer in c#
When should you use a library or a framework vs your own implementation. For
im going to use Sociallib library in my app to interact with social networks.
Is it possible to use a library compiled by visual studio in an application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.