Passing variable to Pyramid controller

98 views Asked by At

I have a queues initiated in the topmost part of the hierarchy of a webapp.

From the main entry point, I put one of those queues in a worker thread and I want to pass the same queue to the Pyramid controller so they can communicate.

This is the main entry point that spins up the threads and Pyramid:

def main(global_config, **settings):
    sql_session = initialize_sql()
    session_factory = SignedCookieSessionFactory(''.join(random.choice(string.printable) for i in range(64)),
                                                 secure=True,
                                                 httponly=True)

    Queues = namedtuple('Queues', 'db requests_from_proxy requests_to_proxy responses')
    queue = Queues(Queue(), Queue(), Queue(), Queue())

    config = Configurator(settings=settings)
    config.include("cornice")
    config.scan("fart.Controller")
    config.set_session_factory(session_factory)
    config.my_queue = queue

    proxy_thread = Thread(target=init_proxy, args=(queue, config,))
    db_thread = Thread(target=init_worker, args=(queue, sql_session,))
    proxy_thread.start()
    db_thread.start()

    return config.make_wsgi_app()

Here is the Controller:

""" Cornice services.
"""
from cornice import Service
import json


request_service = Service(name='request', path='/api/request')

@request_service.get()
def get_request(request):
    print dir()
    return json.dumps(queue.requests_from_proxy.get())

I've spent some hours looking at the documentation and some examples but I cannot figure out how to make the Queue initiated in the main entry point accessible from the Controller. Any ideas?

0

There are 0 answers