Skip to content

Make Server.has_session() use returncode #68

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

Merged
merged 1 commit into from
Mar 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libtmux/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def __init__(self, *args, **kwargs):
self.process.stdout.close()
stderr = self.process.stderr.read()
self.process.stderr.close()
returncode = self.process.returncode
except Exception as e:
logger.error(
'Exception for %s: \n%s' % (
Expand All @@ -197,6 +198,8 @@ def __init__(self, *args, **kwargs):
)
)

self.returncode = returncode

self.stdout = console_to_str(stdout)
self.stdout = self.stdout.split('\n')
self.stdout = list(filter(None, self.stdout)) # filter empty values
Expand Down
19 changes: 3 additions & 16 deletions libtmux/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,24 +334,11 @@ def has_session(self, target_session, exact=True):

proc = self.cmd('has-session', '-t%s' % target_session)

if not proc.stdout:
return True
if any(
x in proc.stdout for x in
['failed to connect to server', 'error connecting to']
):
return False
elif 'no server running' in proc.stdout: # tmux 2.0
return False
elif 'can\'t find session' in proc.stdout: # tmux 2.1
return False
elif 'bad session name' in proc.stdout: # tmux >= 1.9
return False
elif 'session not found' in proc.stdout:
return False
else:
if not proc.returncode:
return True

return False

def kill_server(self):
"""``$ tmux kill-server``."""
self.cmd('kill-server')
Expand Down