MarketSquare / MarketSquare/SSHLibrary
SSHLibrary should not try to "logger.log_background_messages" unless in main thread.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 167
- Forks
- 145
- PR merge metrics
- No merged PRs in 30d
Description
I am in my keyword running some parallel tasks using concurrent.futures and using robotbackgroundlogger to log the messages. After all threads are finished I run logger.log_background_messages() in the main thread since it only allows running it in main thread.
The problem is that SSHLibrary() automatically tries to call logger.log_background_messages() in it’s close function.
From the client.py [source code](https://github.com/MarketSquare/SSHLibrary/blob/master/src/SSHLibrary/client.py) I can see the following snippet
```
def close(self):
"""Closes the connection."""
if self.tunnel:
self.tunnel.close()
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
```
Which means that closing any SSH connection in a thread would raise an error, since you are not allowed to run the function logger.log_background_messages() unless in the main thread.
Something like this could be done,
```
import threading
if threading.current_thread() == threading.main_thread():
try:
logger.log_background_messages()
except AttributeError:
pass
```
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/SSHLibrary/client.py at Client.close and reproduce the issue by closing an SSH connection from a concurrent.futures worker while using robotbackgroundlogger. Verify that background messages are only logged from the main thread, that worker-thread closing no longer raises an error, and that main-thread closing still handles logging.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100