Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python: APScheduler in WSGI app

I would like to run APScheduler which is a part of WSGI (via Apache's modwsgi with 3 workers) webapp. I am new in WSGI world thus I would appreciate if you could resolve my doubts:

  1. If APScheduler is a part of webapp - it becomes alive just after first request (first after start/reset Apache) which is run at least by one worker? Starting/resetting Apache won't start it - at least one request is needed.

  2. What about concurrent requests - would every worker run same set of APScheduler's tasks or there will be only one set shared between all workers?

  3. Would once running process (webapp run via worker) keep alive (so APScheduler's tasks will execute) or it could terminate after some idle time (as a consequence - APScheduler's tasks won't execute)?

Thank you!

like image 704
KoDPI Avatar asked Oct 19 '22 00:10

KoDPI


1 Answers

You're right -- the scheduler won't start until the first request comes in. Therefore running a scheduler in a WSGI worker is not a good idea. A better idea would be to run the scheduler in a separate process and connect to the scheduler when necessary via some RPC mechanism like RPyC or Execnet.

like image 53
Alex Grönholm Avatar answered Oct 21 '22 16:10

Alex Grönholm