Python Wait Until Function Finishes