Git Product home page Git Product logo

Comments (3)

dylwhich avatar dylwhich commented on June 30, 2024

It looks like your problem is caused by reusing the schedule returned by parse_work_schedule, rather than where the functions are defined; you can see this by swapping the order in which you call sched -- only the last one called will actually be scheduled (this is expected, since do will just overwrite the job function each time it's called).

Instead, you could try something like changing all to a lambda so that it returns a new schedule every time:

def parse_work_schedule(self, work):
    options = {
        'all': lambda: self.schedule.every().minute.do,
    }
    return options['all']

and then using it as such:

for work in self.works:
    if sched and sched():
        sched()(pp, work['name'])
        sched()(work['func'], work['name'])
        print 'Scheduled: {0}'.format(sched)
    else:
        print 'Function pointer {0} returned None value.'.format(sched)

from schedule.

denchang avatar denchang commented on June 30, 2024

Hi dylwhich,

I tried your suggestion but it didn't work.

Perhaps I'm not clear with my question (and code).

If you uncomment and comment out:

sched(pp, work['name'])
# sched(work['func'], work['name'])

The code, as it is, works. However, when the comments are swapped, i.e.

# sched(pp, work['name'])
sched(work['func'], work['name'])

the code doesn't work. Why is that? Both are functions.

from schedule.

denchang avatar denchang commented on June 30, 2024

I found the answer. Both are not functions. pp is a function hence it works correctly. But work['func'] is an instancemethod type. So the solution is to have a method within the class that returns a function object. Then I can provide that function object to the schedule.

Thanks for your help.

from schedule.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.