Problem passing parameters to a job handler in APScheduler

1,060 views
Skip to first unread message

Braun Brelin

unread,
Apr 5, 2013, 3:27:43 PM4/5/13
to apsch...@googlegroups.com
Hello all,

I have code that looks like this:

#/usr/bin/env python
from apscheduler.scheduler import Scheduler
import logging

def job_handler(mybar,mybaz):
   print "mybar = " + mybar + "mybaz = " + mybaz
 


s = Scheduler()
s.start()

bar = "bar"
baz = "baz"

s.add_cron_job(lambda: job_handler(bar,baz),hour=20, minute=20,second=25

bar = "notbar"
baz = "notbaz"
s.add_cron_job(lambda: job_handler(bar,baz),hour=20,minute=20,second=35)

while 1:
    pass



The output is always "notbar notbaz" for both cron jobs.
Can someone tell me why this is?  Obviously, I was hoping for the first cron job to print "bar, baz".
How would I fix this?

Thanks,

Braun Brelin


Alex Grönholm

unread,
Apr 7, 2013, 1:43:27 PM4/7/13
to apsch...@googlegroups.com
It's because they both operate on the same closure, where bar is
"notbar" and "baz" is notbaz.
> How would I fix this?
By handing over the arguments the way you're supposed to:

s.add_cron_job(job_handler, hour=20, minute=20, second=35, args=('bar',
'baz'))
>
> Thanks,
>
> Braun Brelin
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "APScheduler" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to apscheduler...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Braun Brelin

unread,
Apr 7, 2013, 1:57:31 PM4/7/13
to apsch...@googlegroups.com
Thanks for the update.  I didn't see the "args" parameter documented anywhere???

Braun




Thanks,

Braun Brelin

To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
You received this message because you are subscribed to a topic in the Google Groups "APScheduler" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/apscheduler/dl-hULBo3sI/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to apscheduler+unsubscribe@googlegroups.com.

Alex Grönholm

unread,
Apr 7, 2013, 8:08:09 PM4/7/13
to apsch...@googlegroups.com
07.04.2013 20:57, Braun Brelin kirjoitti:
Thanks for the update.  I didn't see the "args" parameter documented anywhere???


Thanks,

Braun Brelin

To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
You received this message because you are subscribed to a topic in the Google Groups "APScheduler" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/apscheduler/dl-hULBo3sI/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to apscheduler...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
You received this message because you are subscribed to the Google Groups "APScheduler" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com.

Braun Brelin

unread,
Apr 8, 2013, 7:19:03 AM4/8/13
to apsch...@googlegroups.com
But that's in the 3.0.0 dev documentation.  It should be noted that when I run easy_install to install APScheduler, it installs the 2.1.0 version.  If that's true for me, then it is probably true for most people using APScheduler, especially those that haven't used it before. 

It's the 2.1 docs that I've been working off of since I don't know what's changed between 2.1.0 and 3.0.0.  Given that it's a major version release, I suspect that the changes have been somewhat substantial. 

Note that I can't find any reference to an args parameter in the 2.1.0 documentation at all. 

Braun Brelin

Alex Grönholm

unread,
Apr 8, 2013, 7:34:55 AM4/8/13
to apsch...@googlegroups.com
08.04.2013 14:19, Braun Brelin kirjoitti:
But that's in the 3.0.0 dev documentation.  It should be noted that when I run easy_install to install APScheduler, it installs the 2.1.0 version.  If that's true for me, then it is probably true for most people using APScheduler, especially those that haven't used it before. 

It's the 2.1 docs that I've been working off of since I don't know what's changed between 2.1.0 and 3.0.0.  Given that it's a major version release, I suspect that the changes have been somewhat substantial.
Not yet.

 

Note that I can't find any reference to an args parameter in the 2.1.0 documentation at all. 
It's in the same place: https://apscheduler.readthedocs.org/en/v2.1.0/modules/scheduler.html#apscheduler.scheduler.Scheduler.add_cron_job

The "args" argument has been documented since the beginning (I can find it in the v1.3.1 docs).

Braun Brelin

unread,
Apr 8, 2013, 7:40:07 AM4/8/13
to apsch...@googlegroups.com
I was using the following page for documentation:

https://apscheduler.readthedocs.org/en/latest/cronschedule.html

Braun

Alex Grönholm

unread,
Apr 8, 2013, 8:10:50 AM4/8/13
to apsch...@googlegroups.com
08.04.2013 14:40, Braun Brelin kirjoitti:
I was using the following page for documentation:

https://apscheduler.readthedocs.org/en/latest/cronschedule.html

That's the tutorial, not the API documentation.
Reply all
Reply to author
Forward
0 new messages