How to prevent bottle from handling signals
Question: I am building an application using the Bottle web-framework.

I would like to catch signals USR1 and USR2 to do some work aside from the
bottle server. Mainly I want to be able to reload configuration without
shutting down the web server because I want some objects to live on.

I tried to handle the signals (USR1 and USR2) on my own using :

    
    
    signal.signal(signal.SIGUSR1, my_handler)
    

The problem is that, upon receiving a sigUSR1, the bottle web server crashes
with the following trace :

    
    
    Traceback (most recent call last):
      File "giomanager.py", line 46, in <module>
        run( giomanager, port=60200 )
      File "/usr/lib/python2.7/dist-packages/bottle.py", line 2389, in run
        server.run(app)
      File "/usr/lib/python2.7/dist-packages/bottle.py", line 2087, in run
        srv.serve_forever()
      File "/usr/lib/python2.7/SocketServer.py", line 225, in serve_forever
        r, w, e = select.select([self], [], [], poll_interval)
    select.error: (4, 'Interrupted system call')
    

Do you have an idea why is this happening ? Is it possible to prevent bottle
from receiving those signals ?


Answer: You didn't post your code, so I'm guessing that it might boil down to
something like this:

    
    
    import signal
    from bottle import route, run
    
    def my_handler(*args):
        print 'in signal handler', args
    
    signal.signal(signal.SIGUSR1, my_handler)
    
    @route('/hello')
    def hello():
        return "Hello World!\n"
    
    run(host='localhost', port=8080, debug=True)
    

Which, incidentally, works for me--it prints "in signal handler."

**But** : what I really wanted to suggest is that you consider another
mechanism altogether for refreshing your data. I've had much success with a
separate refresh thread that repeatedly sleeps for some duration, then wakes
up and polls a certain file (or url) to see if there's new data.

There are several reasons why this might be better than using signals, not
least of which is that it'll be a pain (or impossible) to signal each process
if you ever run multi-process. Besides, you weren't planning on running the
Bottle development server in production, were you? (It's [not
recommended](http://bottlepy.org/docs/dev/deployment.html#server-options) for
anything but the smallest of apps.) Given that, once you run your Bottle app
within another webserver, signal handling becomes tricky.

