Might have fixed deadlock by polling in mainloop.