Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close_all_connections() raise RuntimeError when called in a thread #419

Open
doyou89 opened this issue Jul 6, 2022 · 0 comments
Open

close_all_connections() raise RuntimeError when called in a thread #419

doyou89 opened this issue Jul 6, 2022 · 0 comments

Comments

@doyou89
Copy link

doyou89 commented Jul 6, 2022

In my code, SSHLibrary used like below and this code is run by another thread:

SSHLibrary(...).open_connection(...)
# do something here
SSHLibrary.close_all_connections()

This raise exception:

File "/p4_ws/doyou89.jung/workspace/projects/cosmos/.venv/lib/python3.8/site-packages/SSHLibrary/library.py", line 765, in close_all_connections
    self._connections.close_all()
  File "/p4_ws/doyou89.jung/workspace/projects/cosmos/.venv/lib/python3.8/site-packages/SSHLibrary/sshconnectioncache.py", line 27, in close_all
    connection.close()
  File "/p4_ws/doyou89.jung/workspace/projects/cosmos/.venv/lib/python3.8/site-packages/SSHLibrary/pythonclient.py", line 302, in close
    return super(PythonSSHClient, self).close()
  File "/p4_ws/doyou89.jung/workspace/projects/cosmos/.venv/lib/python3.8/site-packages/SSHLibrary/abstractclient.py", line 160, in close
    logger.log_background_messages()
  File "/p4_ws/doyou89.jung/workspace/projects/cosmos/.venv/lib/python3.8/site-packages/robotbackgroundlogger.py", line 101, in log_background_messages
    raise RuntimeError(
RuntimeError: Logging background messages is only allowed from the main thread. Current thread name: schedule_commands_01

Because close() method in abstractclient.py do not handle RuntimeError, the code of close() is:

def close(self):
        """Closes the connection."""
        self._sftp_client = None
        self._scp_transfer_client = None
        self._scp_all_client = None
        self._shell = None
        self.client.close()
        try:
            logger.log_background_messages()
        except AttributeError:
            pass

I think RuntimeError should be added here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant