When I tried the script of Tanaike I found that I needed to put a time.sleep(2) in the callback, otherwise msg became None and the script stopped. Maybe there is a better way? Because now the execution becomes very slow...