can APScheduler work with Pylons 1.0 or Pyramid ?

318 views
Skip to first unread message

Stéphane Klein

unread,
Jul 9, 2011, 11:35:43 AM7/9/11
to pylons-...@googlegroups.com
Hi,

I wounder if Advanced Python Scheduler (APScheduler) -
http://readthedocs.org/docs/apscheduler/en/latest/ can work with Pyramid
and Pylons 1.0 ?

Thanks for your comments.

Regards,
Stephane
--
St�phane Klein <step...@harobed.org>
blog: http://stephane-klein.info
Twitter: http://twitter.com/klein_stephane
pro: http://www.is-webdesign.com

Karol Tomala

unread,
Jul 9, 2011, 9:43:30 PM7/9/11
to pylons-...@googlegroups.com
W dniu 09.07.2011 17:35, St�phane Klein pisze:

> Hi,
>
> I wounder if Advanced Python Scheduler (APScheduler) -
> http://readthedocs.org/docs/apscheduler/en/latest/ can work with
> Pyramid and Pylons 1.0 ?
>
> Thanks for your comments.
>
> Regards,
> Stephane
Hi.
Sure it can. I've done this for my own web applications. The way you
want to do it is either construct another thread (probably by the means
of a function launched in config/environment.py load_environment()) and
then proceed with most of the tasks you want to schedule, or like I did
it myself, write script detached from the web application (i.e. make_app
function launched by Paster entry point) and then utilize process to
launch your script as a daemon. Writing separate script running as a
daemon won't impact performance of the web app itself in case if you are
up to some resource intensive tasks (which I assume you do).

Best regards,
Karol Tomala

Stéphane Klein

unread,
Jun 16, 2012, 4:52:37 AM6/16/12
to pylons-...@googlegroups.com
The way you
Writing separate script running as a
daemon won't impact performance of the web app itself in case if you are
up to some resource intensive tasks (which I assume you do).

In this source code, do you think daemon can impact performance of the web app ?
It's is a bad idea to start scheduler in my webapp ?

Is there an issue with Global Internal Lock of Python ?

from apscheduler.scheduler import Scheduler
import requests

sched = Scheduler()

@sched.interval_schedule(seconds=10)
def some_job():
    print('start')
    for a in range(1, 10):
        r = requests.get('http://www.google.fr')
        print(r.status_code)

    print('fin')

sched.configure()
sched.start()

from wsgiref.util import setup_testing_defaults
from wsgiref.simple_server import make_server

def simple_app(environ, start_response):
    setup_testing_defaults(environ)

    status = '200 OK'
    headers = [('Content-type', 'text/plain')]

    start_response(status, headers)

    ret = ["%s: %s\n" % (key, value)
           for key, value in environ.iteritems()]
    return ret

httpd = make_server('', 8000, simple_app)
print "Serving on port 8000..."
httpd.serve_forever()
 

Parnell Springmeyer

unread,
Jun 17, 2012, 1:19:57 PM6/17/12
to pylons-...@googlegroups.com
I can't answer your question specifically (someone else may have to do that), but I will say this: cron is the natural "scheduler" on a system and if you're doing anything that's supposed to be in the background or "scheduled" it's nice to put it on cron. Easier to find for other programmers, universal scheduling system, etc…

Additionally, you could use Celery to do work. Schedule a start script as a cronjob and put whatever kind of job you want work to be done for into Celery.

That's how I do it at least.

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msg/pylons-discuss/-/tU8Te4-cm5EJ.
To post to this group, send email to pylons-...@googlegroups.com.
To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.

signature.asc

Daniel Holth

unread,
Jun 18, 2012, 10:07:39 AM6/18/12
to pylons-...@googlegroups.com
APScheduler is great. I like my applications to be self-contained and system independent. So, personally I avoid cron jobs. For a simple single-process webapp it's fine to start out with a scheduler thread. When your application gets more complex you could run APScheduler in a separately managed process such as, if you are using uwsgi, a uwsgi mule.

Your example code will probably spend most of its time waiting for I/O, not holding the GIL.

James Bennett Saxon

unread,
Dec 24, 2014, 2:13:37 PM12/24/14
to pylons-...@googlegroups.com
I'm liking the way I can dynamically schedule APScheduler.

I'm getting tripped up on the pyramid/models/views integration.

Let's suppose I wanted to have all the code together in this single app so I can share models with the scheduling daemon AND the pyramid app.

What's the baseline method for running a python script which bootstraps models and pyramid so I can keep as DRY as possible.  

I see how in the ini files I can add a [pshell] section to pull in models and sessions.  


Is there a place where I can get a full daemon script example?  There are too many words, I'm not making these high level connections.  Too abstract!  :-)

John Anderson

unread,
Dec 28, 2014, 6:14:50 PM12/28/14
to pylons-...@googlegroups.com
On Wed, Dec 24, 2014 at 11:13 AM, James Bennett Saxon <ja...@saxon.com> wrote:
I'm liking the way I can dynamically schedule APScheduler.

I'm getting tripped up on the pyramid/models/views integration.

Let's suppose I wanted to have all the code together in this single app so I can share models with the scheduling daemon AND the pyramid app.

What's the baseline method for running a python script which bootstraps models and pyramid so I can keep as DRY as possible.  

I see how in the ini files I can add a [pshell] section to pull in models and sessions.  


Is there a place where I can get a full daemon script example?  There are too many words, I'm not making these high level connections.  Too abstract!  :-)


No reason to revive 3yr old mailing list posts to ask a question :)

In regards to how to write a script that can bootstrap your application, all you need to do is take an .ini and run bootstrap on it, which is documented in that link you provided.

I'm not sure how APScheduler works (haven't used it), but I have seen https://github.com/cadithealth/pyramid_scheduler/  mentioned as a project that integrates with it. It is fairly new and doesn't have a lot of documentation but might be a good start for you.

If you aren't completely set on the idea of APScheduler you could also use celery as an option, here is an example of how to do scheduled jobs with shared configuration with celery/pyramid_celery:

You define how often you want that task to run:

Declare a task:

You can access the pyramid registry and the whole application will automatically be bootstrapped so your database sessions will automatically work.

Then you just launch the scheduler:

celery worker -A pyramid_celery.celery_app --ini development.ini -B

This is a feature of pyramid_celery 2.0.0-rc2 but I'll release the first stable version of that in a couple of days.

Hope this helps!
Reply all
Reply to author
Forward
0 new messages