title: Interrupt function in python
body: <p>I'm using modbus protocol to communicate with my program. When slave gets signal from master on register 1 he starts function</p>
  
  <pre><code>def main():
  
      #Create the server
      server = modbus_rtu.RtuServer(serial.Serial(PORT))
      server.start()
  
      slave_1 = server.add_slave(1)
      slave_1.add_block('0', cst.HOLDING_REGISTERS, 0, 2)
      slave_1.set_values('0', 0, 0)         #set value on the begining
      slave_1.set_values('0', 1, 0)         #set value on the begining
  
      while True:
  
          register_1 = slave_1.get_values('0', 0, 1)
          register_2 = slave_1.get_values('0', 1, 1)
  
  
          if register_1[0] == 1:
  
              time.sleep(3)
              slave_1.set_values('0', 0, 1)
              time.sleep(3)
              slave_1.set_values('0', 0, 0)
  </code></pre>
  
  <p>I want stop this function when I change state on register 2 for few seconds, after this time it should come back to place when it was stopped.
  It should be immediately, so I can not check this is normal "if".
  It should by similar like interrupt in arduino.</p>
  
  <p>Question: How can I create this interrupt?</p>