Our ListeningThread class will need to inherit from threading.Thread and contain a run method, which can happen in the background.
Since we want to be always checking for new messages until the user closes their ChatWindow, we shall put our request inside a loop which the ChatWindow will be able to end when closed.
Let's begin our ListeningThread class, as follows:
import arrowimport threadingimport timefrom requester import Requester
Our class will be making use of the following modules:
- arrow: This is used to create the timestamps
- threading: This is used to run in the background
- time: This is used to sleep for two seconds between requests
- requester: This is used to contact our web service
With the imports taken ...