Here in this code there are at least two things that are not really good.
First, don't use ready(). It has a specific meaning (see documentation, that states: "Returns: True if the next read() is...