Semi-synchronous programming in python