Navigation Menu

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

tmux freeze fails #239

Closed
kaushalmodi opened this issue Apr 21, 2017 · 25 comments · Fixed by tmux-python/libtmux#37
Closed

tmux freeze fails #239

kaushalmodi opened this issue Apr 21, 2017 · 25 comments · Fixed by tmux-python/libtmux#37

Comments

@kaushalmodi
Copy link

kaushalmodi commented Apr 21, 2017

Hi,

I just installed tmuxp using pip3 install tmuxp. It believed it installed fine because if I type just tmuxp, it shows the help.

I have a tmux session named main. But when I typed tmuxp freeze main, I got this backtrace:

> tmuxp freeze main
Traceback (most recent call last):
  File "/home/kmodi/stowed/bin/tmuxp", line 11, in <module>
    load_entry_point('tmuxp==1.2.8', 'console_scripts', 'tmuxp')()
  File "/home/kmodi/stow/pkgs/python/3.6.1/lib/python3.6/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/kmodi/stow/pkgs/python/3.6.1/lib/python3.6/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/kmodi/stow/pkgs/python/3.6.1/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/kmodi/stow/pkgs/python/3.6.1/lib/python3.6/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/kmodi/stow/pkgs/python/3.6.1/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/kmodi/stow/pkgs/python/3.6.1/lib/python3.6/site-packages/tmuxp/cli.py", line 387, in command_freeze
    sconf = freeze(session)
  File "/home/kmodi/stow/pkgs/python/3.6.1/lib/python3.6/site-packages/tmuxp/workspacebuilder.py", line 324, in freeze
    'options': w.show_window_options(),
  File "/home/kmodi/stow/pkgs/python/3.6.1/lib/python3.6/site-packages/libtmux/window.py", line 195, in show_window_options
    window_options = dict(cmd)
ValueError: dictionary update sequence element #2 has length 4; 2 is required

Python version: 3.6.1
OS: RHEL 6.6

@kaushalmodi
Copy link
Author

To add, I was able to do tmuxp load example.yaml as explained on the QuickStart page.

@tony
Copy link
Member

tony commented Apr 26, 2017

Can you try to recreate the settings and return the results of tmux list-sessions, tmux list-windows -a, and tmux list-panes -a?

@kaushalmodi
Copy link
Author

Can you try to recreate the settings

I did not follow that.

Also, I am using tmux version 2.4+ (built from its master branch).

return the results of tmux list-sessions, tmux list-windows -a, and tmux list-panes -a

> tmuxp freeze main                                                                                   04/26 4:01pm
Traceback (most recent call last):
  File "/home/kmodi/stowed/bin/tmuxp", line 11, in <module>
    load_entry_point('tmuxp==1.2.8', 'console_scripts', 'tmuxp')()
  File "/home/kmodi/stow/pkgs/python/3.6.1/lib/python3.6/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/kmodi/stow/pkgs/python/3.6.1/lib/python3.6/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/kmodi/stow/pkgs/python/3.6.1/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/kmodi/stow/pkgs/python/3.6.1/lib/python3.6/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/kmodi/stow/pkgs/python/3.6.1/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/kmodi/stow/pkgs/python/3.6.1/lib/python3.6/site-packages/tmuxp/cli.py", line 387, in command_freeze
    sconf = freeze(session)
  File "/home/kmodi/stow/pkgs/python/3.6.1/lib/python3.6/site-packages/tmuxp/workspacebuilder.py", line 324, in freeze
    'options': w.show_window_options(),
  File "/home/kmodi/stow/pkgs/python/3.6.1/lib/python3.6/site-packages/libtmux/window.py", line 195, in show_window_options
    window_options = dict(cmd)
ValueError: dictionary update sequence element #2 has length 4; 2 is required

> tmux list-sessions                                                                                  04/26 4:01pm
main: 9 windows (created Thu Apr 20 09:55:52 2017) [283x63] (attached)
servers: 2 windows (created Fri Apr 21 18:50:06 2017) [283x63]

> tmux list-windows -a                                                                                04/26 4:01pm
main:1: *scratch* (4 panes) [283x63]
main:2: tok1#- (4 panes) [283x63]
main:3: tok2* (4 panes) [283x63]
main:4: tok_cosim (3 panes) [283x63]
main:5: tok-regr (3 panes) [283x62]
main:6: dummy (3 panes) [283x62]
main:7: uvm_lib (1 panes) [283x62]
main:8: sandbox (3 panes) [283x62]
main:9: hugo (2 panes) [283x63]
servers:1: hugo* (4 panes) [283x63]
servers:2: weekly#- (1 panes) [283x62]

> tmux list-panes -a                                                                                  04/26 4:01pm
main:1.1: [146x39] [history 98331/100000, 29301238 bytes] %32
main:1.2: [146x22] [history 51000/100000, 26909251 bytes] %35
main:1.3: [136x40] [history 94715/100000, 32594592 bytes] %34 (active)
main:1.4: [136x21] [history 89261/100000, 48831149 bytes] %33
main:2.1: [152x38] [history 92158/100000, 37348284 bytes] %28
main:2.2: [152x23] [history 95384/100000, 39572096 bytes] %31
main:2.3: [130x38] [history 99757/100000, 39413863 bytes] %30
main:2.4: [130x23] [history 53355/100000, 21578684 bytes] %29 (active)
main:3.1: [137x33] [history 91098/100000, 36639810 bytes] %24
main:3.2: [137x28] [history 94343/100000, 37169779 bytes] %27
main:3.3: [145x31] [history 93209/100000, 40110848 bytes] %26
main:3.4: [145x30] [history 97077/100000, 41350576 bytes] %25 (active)
main:4.1: [141x62] [history 98069/100000, 45437315 bytes] %21
main:4.2: [141x30] [history 99994/100000, 44154107 bytes] %23 (active)
main:4.3: [141x31] [history 81056/100000, 34830069 bytes] %22
main:5.1: [136x61] [history 99054/100000, 39970250 bytes] %18 (active)
main:5.2: [146x30] [history 90399/100000, 37372706 bytes] %20
main:5.3: [146x30] [history 61035/100000, 27441453 bytes] %19
main:6.1: [135x61] [history 54697/100000, 20081802 bytes] %15 (active)
main:6.2: [147x31] [history 2467/100000, 1022452 bytes] %17
main:6.3: [147x29] [history 89384/100000, 39249365 bytes] %16
main:7.1: [283x61] [history 24/100000, 22236 bytes] %14 (active)
main:8.1: [143x61] [history 85435/100000, 51712408 bytes] %11
main:8.2: [139x35] [history 47674/100000, 18936138 bytes] %13
main:8.3: [139x25] [history 1050/100000, 428025 bytes] %12 (active)
main:9.1: [141x62] [history 34177/100000, 9809743 bytes] %2 (active)
main:9.2: [141x62] [history 91141/100000, 26022674 bytes] %9
servers:1.1: [141x31] [history 1074/100000, 259365 bytes] %52
servers:1.2: [141x31] [history 49/100000, 16263 bytes] %53
servers:1.3: [141x30] [history 0/100000, 0 bytes] %54 (active)
servers:1.4: [141x30] [history 0/100000, 0 bytes] %55
servers:2.1: [283x61] [history 0/100000, 0 bytes] %56 (active)

@tony
Copy link
Member

tony commented Apr 26, 2017

Can you try to recreate the settings

Just meant if you could recreate the error, while pulling the info from those commands. It helps me try to figure out what could be causing the glitch.

I'm very interested in the output of tmux show-window-options, but, I don't know which window is causing the crash. I think this may sound like a pain, but could you try returning that command for all windows you have open? Sorry if that may be annoying, I should add in some hooks to make that easier to debug.

@kaushalmodi
Copy link
Author

kaushalmodi commented Apr 26, 2017

I'm very interested in the output of tmux show-window-options, but, I don't know which window is causing the crash. I think this may sound like a pain, but could you try returning that command for all windows you have open? Sorry if that may be annoying, I should add in some hooks to make that easier to debug.

No problem.. Here are the results for tmux show-window-options for each window. I have copied the window names from above for convenience. I am confused why the window options are not the same in all windows. Actually I understood.. It just happens that I never did pane synchronization in the windows with just "automatic-rename off".


main:1: scratch (4 panes) [283x63]

automatic-rename off


main:2: tok1#- (4 panes) [283x63]

automatic-rename off
pane-active-border-style fg=colour63
pane-border-format " #P "
synchronize-panes off


main:3: tok2* (4 panes) [283x63]

automatic-rename off
pane-active-border-style fg=colour63
pane-border-format " #P "
synchronize-panes off


main:4: tok_cosim (3 panes) [283x63]

automatic-rename off
pane-active-border-style fg=colour63
pane-border-format " #P "
synchronize-panes off


main:5: tok-regr (3 panes) [283x62]

automatic-rename off
pane-active-border-style fg=colour63
pane-border-format " #P "
synchronize-panes off


main:6: dummy (3 panes) [283x62]

automatic-rename off
pane-active-border-style fg=colour63
pane-border-format " #P "
synchronize-panes off


main:7: uvm_lib (1 panes) [283x62]

automatic-rename off


main:8: sandbox (3 panes) [283x62]

automatic-rename off


main:9: hugo (2 panes) [283x63]

automatic-rename off
pane-active-border-style fg=colour63
pane-border-format " #P "
synchronize-panes off

@kaushalmodi
Copy link
Author

Now I toggled pane synchronization in all windows. Now all windows show:

automatic-rename off
pane-active-border-style fg=colour63
pane-border-format " #P "
synchronize-panes off

But tmuxp freeze main still throws the same error.

@tony
Copy link
Member

tony commented Apr 26, 2017

I wonder if this were to still happen in 2.4 built from the release changeset.

I think that the pane-border-format looks suspect. Mine is pane-border-format "#{?pane_active,#[reverse],}#{pane_index}#[default] \"#{pane_title}\""

I'm wondering what your tmux configuration looks like. Are you using tmuxp configs as well?

@tony
Copy link
Member

tony commented Apr 26, 2017

Could you try to put a print(cmd) before dict(cmd) in /home/kmodi/stow/pkgs/python/3.6.1/lib/python3.6/site-packages/libtmux/window.py? Then trying freeze again? Maybe they we can get an idea what's causing it

@kaushalmodi
Copy link
Author

I'm wondering what your tmux configuration looks like.

my .tmux.conf

My pane border setup:

setw -g pane-border-status "bottom"
setw -g pane-border-format " #P "

setw  -g pane-active-border-style     fg=colour63,bg=default
setw  -g pane-border-style            fg=colour235,bg=default

bind  C-s if -F '#{pane_synchronized}' \
                     'setw synchronize-panes off; \
                      setw pane-active-border-style fg=colour63,bg=default; \
                      setw pane-border-format       " #P "' \
                   'setw synchronize-panes on; \
                    setw pane-active-border-style fg=red; \
                    setw pane-border-format       " #P - Pane Synchronization ON "'

Are you using tmuxp configs as well?

No, I haven't configured tmuxp in any way, using it as default.

@kaushalmodi
Copy link
Author

I think that the pane-border-format looks suspect.

Your suspicion was correct!

[('automatic-rename', 'off')]
[('automatic-rename', 'off'), ('pane-active-border-style', 'fg=colour63'), ('pane-border-format', '"', '#P', '"'), ('synchronize-panes', 'off')]

('pane-border-format', '"', '#P', '"')

So looks like tmuxp needs to allow spaces in pane-border-format.

@tony
Copy link
Member

tony commented Apr 26, 2017

Interested in trying a PR? It's something that could be done via the tests. Or I could give it a go.

@kaushalmodi
Copy link
Author

I wish I could help. While I can understand Python scripts with help from google, SO, etc, I don't think I can tackle this.. But still let me give it a try.

I can now run tmuxp freeze main after ensuring that the pane-border-format did not have spaces.

tmuxp freeze main                                                                                                           04/26 4:58pm
[('automatic-rename', 'off'), ('pane-active-border-style', 'fg=colour63'), ('pane-border-format', '"#P"'), ('synchronize-panes', 'off')]
[('automatic-rename', 'off'), ('pane-active-border-style', 'fg=colour63'), ('pane-border-format', '"#P"'), ('synchronize-panes', 'off')]
[('automatic-rename', 'off'), ('pane-active-border-style', 'fg=colour63'), ('pane-border-format', '"#P"'), ('synchronize-panes', 'off')]
[('automatic-rename', 'off'), ('pane-active-border-style', 'fg=colour63'), ('pane-border-format', '"#P"'), ('synchronize-panes', 'off')]
[('automatic-rename', 'off'), ('pane-active-border-style', 'fg=colour63'), ('pane-border-format', '"#P"'), ('synchronize-panes', 'off')]
[('automatic-rename', 'off'), ('pane-active-border-style', 'fg=colour63'), ('pane-border-format', '"#P"'), ('synchronize-panes', 'off')]
[('automatic-rename', 'off'), ('pane-active-border-style', 'fg=colour63'), ('pane-border-format', '"#P"'), ('synchronize-panes', 'off')]
[('automatic-rename', 'off'), ('pane-active-border-style', 'fg=colour63'), ('pane-border-format', '"#P"'), ('synchronize-panes', 'off')]
[('automatic-rename', 'off'), ('pane-active-border-style', 'fg=colour63'), ('pane-border-format', '"#P"'), ('synchronize-panes', 'off')]
Convert to [yaml]: yaml

@kaushalmodi
Copy link
Author

It's something that could be done via the tests.

While I can try fixing this, not sure if I can write tests for that :)

@tony
Copy link
Member

tony commented Apr 26, 2017

You're welcome to try a suggestion and post it here, but it's not helpful without a regression test. It should be relatively easy to add.

https://github.com/tony/tmuxp/blob/6eabe5e6e5c177197788761eeff737b747e70a7e/tests/test_workspacebuilder.py#L238
https://github.com/tony/tmuxp/blob/master/tests/fixtures/workspacebuilder/window_options.yaml

Adding a pane-border-format: ' #P ' and making that test pass.

make test='tests/test_workspacebuilder.py::test_window_options'

It may only require editing fixtures/workspacebuilder/window_options.yaml and seeing what it takes to make it go green. One issue though, the fix to this seems to be libtmux related. So libtmux would need to get checked out and installed to tmuxp via pip install -e path/to/libtmux.

Seem like too much work? Need time? What do you think?

@kaushalmodi
Copy link
Author

This fixes stuff from my quick testing:

diff --git a/libtmux/window.py b/libtmux/window.py
index 4b70919..d1e3cb1 100644
--- a/libtmux/window.py
+++ b/libtmux/window.py
@@ -9,6 +9,8 @@ from __future__ import absolute_import, unicode_literals, with_statement
 
 import logging
 import os
+# http://stackoverflow.com/a/79985
+import shlex # For .split function to allow splitting that retains quoted sub-strings
 
 from . import exc, formats
 from .common import TmuxMappingObject, TmuxRelationalObject
@@ -190,7 +192,7 @@ class Window(TmuxMappingObject, TmuxRelationalObject):
                 *tmux_args
             ).stdout
 
-        cmd = [tuple(item.split(' ')) for item in cmd]
+        cmd = [tuple(shlex.split(item)) for item in cmd]
 
         window_options = dict(cmd)

Any objections to adding this new dependency?

@tony
Copy link
Member

tony commented Apr 26, 2017

Looks like an idea, why not try making a PR to libtmux. I'll add a test on both ends.

An aside: No need to reference SO for something simple as that, by the way. tmuxp is BSD licensed and we don't want to appear like we're taking viral CC SA (share alike) code.

No need to comment the import, but you can add move that comment to the line above cmd = [tuple(shlex.split(item)) for item in cmd]

kaushalmodi added a commit to kaushalmodi/libtmux that referenced this issue Apr 26, 2017
Fixes tmux-python/tmuxp#239

With the below in tmux config:

    setw -g pane-border-format " #P "

Before the fix:

    ('pane-border-format', '"', '#P', '"')

After the fix:

    ('pane-border-format', ' #P ')
@kaushalmodi
Copy link
Author

kaushalmodi commented Apr 26, 2017

Looks like an idea, why not try making a PR to libtmux.

Done! ( tmux-python/libtmux#37 )

I'll add a test on both ends.

Yes, can you please do that this time.. I will observe and learn how you updated the tests.

An aside: No need to reference SO for something simple as that, by the way. tmuxp is BSD licensed and we don't want to appear like we're taking viral CC SA (share alike) code. No need to comment the import, but you can add move that comment to the line above cmd = [tuple(shlex.split(item)) for item in cmd]

The PR has your suggestions applied.

Thanks!

@kaushalmodi
Copy link
Author

kaushalmodi commented Apr 26, 2017

Oh well, looks like things are failing. I'll get some time at later to understand how the shlex.split impacted the tests.

@tony
Copy link
Member

tony commented Apr 26, 2017

Take your time. If you need to take a different approach, that's fine too.

@kaushalmodi
Copy link
Author

May be shlex works on Python 2.7+ only?

image

@tony
Copy link
Member

tony commented Apr 26, 2017

Another thing about shlex:

Prior to Python 2.7.3, this module did not support Unicode input.

@tony
Copy link
Member

tony commented Apr 26, 2017

This means that 2.6 support would have to be dropped. In libtmux, and therefore tmuxp, too.

2.6 was asked about back in 2013 @ #13. I'm willing to weigh dropping 2.6 support if you can't find an approach.

@kaushalmodi
Copy link
Author

Prior to Python 2.7.3, this module did not support Unicode input.

Yes, I was reading shlex documentation, but don't know what

assert window.show_window_options()['main-pane-height'] == 40

has to do with Unicode support.

I'm willing to weigh dropping 2.6 support if you can't find an approach.

Thanks for the consideration. I wouldn't rely on my ability to find a different approach as I am not a serious Python coder. I can even keep on using my forked version with the fix.

@tony
Copy link
Member

tony commented Apr 26, 2017

I am going to consider loosening the 2.6 requirement. It's been almost 4 years since that issue.

Last 2.6 release was 2.6.9 in October 29, 2013. Support ended then.

tony pushed a commit to kaushalmodi/libtmux that referenced this issue Apr 27, 2017
Fixes tmux-python/tmuxp#239

With the below in tmux config:

    setw -g pane-border-format " #P "

Before the fix:

    ('pane-border-format', '"', '#P', '"')

After the fix:

    ('pane-border-format', ' #P ')
@tony tony reopened this Apr 28, 2017
@tony tony closed this as completed in #248 Apr 28, 2017
@tony
Copy link
Member

tony commented Apr 28, 2017

This is live in 1.3.0

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

Successfully merging a pull request may close this issue.

2 participants