get "Alarm Clock when send data with python-stompy (orbited)"

252 Views Asked by At

I would like to make a log monitor, so it monitors log and parses the log then save to the db and push that data via stomp. Yeah, it succeeds to push the data, but after I push the data, I get the error message > "Alarm Clock" and the program stopped !

This is my code:

def sent_msg(msg,channel)    
    try:
        stomp = Client(host="localhost", port=54123)
        stomp.connect()
        stomp.subscribe(channel)
        signal.alarm(1)
        stomp.put(msg, destination=channel)
        signal.alarm(0)
    except Exception,err:
        print err
    else:
        print 'succes'


try:
    msg = """
    <td>%s</td>
    <td>%s</td>
    <td>%s</td>
    <td>%s</td>
    <td>%s</td>
    """%(ip,dt,time,ua,req)
    sent_msg(msg,'/monitor_sqli')
except Exception, err:
    print err
else:
    print 'exist'
1

There are 1 best solutions below

0
Tyson On

Move signal.alarm(0) into a finally: block after your first else: block to ensure the alarm is cleared regardless of stomp.push(msg, destination=channel) being successful or not.

Doing this will help you focus on the real cause of the failure, which I suspect is the result of an exception being thrown by stomp.push(msg, destination=channel) - perhaps because the return value from the remote server cannot be parsed by the stomp library.