One solution I can think of is making a custom server runner in your pylons app and
doing this special initialization there.
I suggest moving all this special code in a special module in your pylons app (lets
say "async.py" for reference here).
So you would have the engine code here and the custom server runner:
class Engine:
....
from cogen.web.wsgi import Runner
from cogen.web.wsgi import local
pubsub = PublishSubscribeQueue()
engine = Engine(pubsub)
def server_runner(app, global_conf, host, port, **options):
port = int(port)
try:
import paste.util.threadinglocal as pastelocal
pastelocal.local = local
except ImportError:
pass
runner = Runner(host, port, app, options)
runner.sched.add(engine.tick)
runner.run()
Then you would have to edit your setup.py to add a special server runner entry point:
In entry_points add:
[paste.server_runner]
hijacked_runner = pylonsappname.async:server_runner
And finally change the development.ini of whatever you are running paste with to have
something like:
[server:main]
use = egg:pylonsappname#hijacked_runner
--
ionel