#StackBounty: #python #python-3.x #decorator Pass a decorator's function into Python RQ

Bounty: 50

How do I pass a decorator’s function into a job?

I have a decorator that would run a job using the function.

def queueFunction(passedFunction, *args, **kwargs):
    # Do some stuff
    passedFunction(*args, **kwargs)

def myDecorator(async=True):
    def wrapper(function):
        def wrappedFunc(*args, **kwargs):
            data = DEFAULT_DATA
            if async:
                queueFunction.delay(function, *args, **kwargs)
                data = queueFunction(function, *args, **kwargs)
            return data
        return wrappedFunc
    return wrapper

I get an error when trying to use it.

Can't pickle <function Model.passedFunction at 0x7f410ad4a048>: it's not the same object as modelInstance.models.Model.passedFunction

Using Python 3.4

Get this bounty!!!

Example of Decorator Pattern – LowerCaseInputStream

Create a LowerCaseInputStream class as follows

public class LowerCaseInputStream extends FilterInputStream 

    public LowerCaseInputStream(InputStream in) {
    public int read() throws IOException
        int c = super.read();
            return c;
            return Character.toLowerCase(c);
    public int read(byte b[], int offset, int len) throws IOException
        int result = super.read(b, offset, len);
        for (int i = offset; i < offset+result; i++) 
            b[i] = (byte)Character.toLowerCase((char)b[i]);
        return result;

Use LowerCaseInputStream as follows

public static void main(String[] args) throws FileNotFoundException {
        FileInputStream fis = new FileInputStream("D:\Yogesh.txt");
        BufferedInputStream bufin = new BufferedInputStream(fis);
        InputStream in = new LowerCaseInputStream(bufin);
        int c;
        catch(Exception e)

Find it really interesting? You can read more about Decorator pattern in Head First Design Pattern book.