[program:my_scheduler]
command={my_site_path}/web2py.py -K my_app#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
if '__file__' in globals():
path = os.path.dirname(os.path.abspath(__file__))
os.chdir(path)
else:
path = os.getcwd()
sys.path = [path]+[p for p in sys.path if not p==path]
from gluon.shell import run
from gluon import main
import logging
logging.getLogger().setLevel(logging.INFO)
if __name__ == '__main__':
code = "from gluon import current; current._scheduler.loop()"
app = 'myapp'
run(app,True,True,None,False,code)
Because web2py lets you launch multiple schedulers with web2py.py -K myapp,myapp or web2py.py -K myapp1,myapp2 the actual scheduler process is a subprocess of the main one you launch with web2py.py.
If you launch with the "external" method, as python gluon/scheduler.py -t tasks.py -f .... etc no subprocess is spawned and then the PID reported on the scheduler_worker table is the same one you have on "console".
Obviously a scheduler spawns a process for every task processed (that's the whole point of the scheduler) but there's no "master" spawning the scheduler itself.
BTW, I'm working on having the "embedded mode" to terminate all workers processes spawned when the "master" is killed. It's on the feature list.
PS: for the moment you can make a script to work as "embedded mode" and with no subprocesses spawned. Place it in the same folder where web2py.py lives. This will run a single scheduler process with no subprocesses
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gluon.shell import run
from gluon import main
import logging
logging.getLogger().setLevel(logging.INFO)
if __name__ == '__main__':
code = "from gluon import current; current._scheduler.loop()"
app = 'myapp'
run(app,True,True,None,False,code)
Because web2py lets you launch multiple schedulers with web2py.py -K myapp,myapp or web2py.py -K myapp1,myapp2 the actual scheduler process is a subprocess of the main one you launch with web2py.py.
If you launch with the "external" method, as python gluon/scheduler.py -t tasks.py -f .... etc no subprocess is spawned and then the PID reported on the scheduler_worker table is the same one you have on "console".
Obviously a scheduler spawns a process for every task processed (that's the whole point of the scheduler) but there's no "master" spawning the scheduler itself.
BTW, I'm working on having the "embedded mode" to terminate all workers processes spawned when the "master" is killed. It's on the feature list.
PS: for the moment you can make a script to work as "embedded mode" and with no subprocesses spawned. Place it in the same folder where web2py.py lives. This will run a single scheduler process with no subprocesses
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
if '__file__' in globals():
path = os.path.dirname(os.path.abspath(__file__))
os.chdir(path)
else:
path = os.getcwd()
sys.path = [path]+[p for p in sys.path if not p==path]
from gluon.shell import run
from gluon import main
import logging
logging.getLogger().setLevel(logging.INFO)
if __name__ == '__main__':
code = "from gluon import current; current._scheduler.loop()"
app = 'myapp'
run(app,True,True,None,False,code)
--