SIkwan
SIkwan

Reputation: 379

Web.py daemon communication

I try to create a web server using web.py in order to talk with a daemon.

The goal is to send commands via HTTP to my web.py (executed in a thread opened by my main daemon); then use a pipe to transmit the commands to my main program.

The final program will have several process and threads, and the web.py interface will be the entry point of the software.

My problem is that web.py instanciate a new class for each request, so I can't find an easy way to pass my pipe to the request handlers. I tried using hooks or processors but it doesn't seems to work.

Have someone succeed to pass an object to the web.py handler ? Or is there a way to store objects somewhere in the web object ?

Upvotes: 1

Views: 273

Answers (1)

SIkwan
SIkwan

Reputation: 379

I found the solution but it is not crystal clear in the documentation.

I just created a load_hook using web.ctx to store my object :

def load_hook():
    web.ctx.pipe = input_p

app = web.application(urls, globals())
    app.add_processor(web.loadhook(load_hook))
    app.run()

Then I can access web.ctx.pipe in all my classes. Quite simple to do but hard to find in the documentation.

Upvotes: 1

Related Questions