Added 'on_interrupt' to close sockets and stuff before actually interrupting thread to avoid lock-ups.