Search Results

Search found 2 results on 1 pages for 'defnull'.

Page 1/1 | 1 

  • threading.local equivalent for twisted.web?

    - by defnull
    In asynchronous environments, threading.local is not guaranteed to be context-local anymore, because several contexts may coexist within a single thread. Most asynchronous frameworks (gevent, eventlet) provide a get_current_context() functionality to identify the current context. Some offer a way to monkey-patch threading.local so it is local to 'greenthreads' or other framework-specific contexts. I cannot find such a functionality in the twisted documentation. How do I do this?

    Read the article

  • How to differentiate between method and function in a decorator?

    - by defnull
    I want to write a decorator that acts differently depending on whether it is applied to a function or to a method. def some_decorator(func): if the_magic_happens_here(func): # <---- Point of interest print 'Yay, found a method ^_^ (unbound jet)' else: print 'Meh, just an ordinary function :/' return func class MyClass(object): @some_decorator def method(self): pass @some_decorator def function(): pass I tried inspect.ismethod(), inspect.ismethoddescriptor() and inspect.isfunction() but no luck. The problem is that a method actually is neither a bound nor an unbound method but an ordinary function as long as it is accessed from within the class body. What I really want to do is to delay the actions of the decorator to the point the class is actually instantiated because I need the methods to be callable in their instance scope. For this, I want to mark methods with an attribute and later search for these attributes when the .__new__() method of MyClass is called. The classes for which this decorator should work are required to inherit from a class that is under my control. You can use that fact for your solution. In the case of a normal function the delay is not necessary and the decorator should take action immediately. That is why I wand to differentiate these two cases.

    Read the article

1