MUK
MUK

Reputation: 411

function that takes a tmux session and restarts it

I want to write a customize program in libtmux, that takes input of session name, stop that session and restart it.

def new_function():

    import libtmux
    server = libtmux.Server()
    print server.list_sessions()
    session= input('Enter Session Name:')
    print (session)
    my_session = server.find_where({"session_name": session})

    server.attach_session(target_session=my_session)


if __name__ == '__main__':
    print '............'

    new_function()

It prints the sessions in tmux and takes a input but crash right after it. After entering the session name , I want it to stop that session and restarts it.

Upvotes: 0

Views: 428

Answers (1)

atline
atline

Reputation: 31614

See next sourcecode in /usr/local/lib/python3.4/dist-packages/libtmux/server.py, the para target_session should be a string, the name of the session.

In your place, it is session, not my_session, my_session's type is libtmux.session.Session not string, so server.attach_session(target_session=my_session) crash.

def attach_session(self, target_session=None):
    """``$ tmux attach-session`` aka alias: ``$ tmux attach``.

    :param: target_session: str. name of the session. fnmatch(3) works.
    :raises: :exc:`exc.BadSessionName`
    """

In fact, you did not need this function, you just need to use kill_session & new_session to make your aims.

Upvotes: 1

Related Questions