Slow response by arduino server being controlled by python client

How would you recommend refactoring the port opening / closing to optimize for speed?