Skip to content

Decide if Titta needs a PR for TalkToProLab's run() #16

@anna-stacey

Description

@anna-stacey

While moving around self.__stop = True (see other issue), I kept getting this error:

Traceback (most recent call last):
  File "C:\Program Files\PsychoPy\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\Anna\Documents\Wiigwaas\Titta\titta\TalkToProLab.py", line 65, in run
    self.clock_address.ping()
  File "C:\Program Files\PsychoPy\lib\site-packages\websocket\_core.py", line 330, in ping
    self.send(payload, ABNF.OPCODE_PING)
  File "C:\Program Files\PsychoPy\lib\site-packages\websocket\_core.py", line 283, in send
    return self.send_frame(frame)
  File "C:\Program Files\PsychoPy\lib\site-packages\websocket\_core.py", line 311, in send_frame
    l = self._send(data)
  File "C:\Program Files\PsychoPy\lib\site-packages\websocket\_core.py", line 515, in _send
    return send(self.sock, data)
  File "C:\Program Files\PsychoPy\lib\site-packages\websocket\_socket.py", line 146, in send
    raise WebSocketConnectionClosedException("socket is already closed.")
websocket._exceptions.WebSocketConnectionClosedException: socket is already closed.

You'd think this wouldn't happen, since run looks like this:

    def run(self):
        ''' Ping/pong the server every 15 s to keep the connection alive.
        Starts the thread that keeps the connection alive.
        Otherwise, if there is not communication between the server and client,
        the connection dies after 30 sec.
        '''

        while True:
            self.clock_address.ping()
            self.clock_address.pong("pong")
            
            self.external_presenter_address.ping()
            self.external_presenter_address.pong("pong")
            
            self.project_address.ping()
            self.project_address.pong("pong")
            
            time.sleep(15)
            
            if self.__stop == True:
                break

So, I guess, somehow the connection is being severed after the check at the bottom, but before the first command in the loop? Ugh. Is this being caused by me moving the statement...? Seems relevant, but why would this occur?
Anyways, it seems to not happen if I change run() to the following, which as far as I can tell is essentially equivalent (though slightly simpler):

    def run(self):
        ''' Ping/pong the server every 15 s to keep the connection alive.
        Starts the thread that keeps the connection alive.
        Otherwise, if there is not communication between the server and client,
        the connection dies after 30 sec.
        '''

        while self.__stop:
            self.clock_address.ping()
            self.clock_address.pong("pong")
            
            self.external_presenter_address.ping()
            self.external_presenter_address.pong("pong")
            
            self.project_address.ping()
            self.project_address.pong("pong")
            
            time.sleep(15)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions