jupyenv icon indicating copy to clipboard operation
jupyenv copied to clipboard

next-bug/bash kernel raises ': 1" exception on every cell run

Open djacu opened this issue 1 year ago • 2 comments

Describe the bug Exception ": 1" raised on every cell when using the bash kernel in JupyterLab.

To Reproduce Start jupyter lab Open a new notebook using the example bash kernel Run any command It will run the command but also show an exception below, : 1.

Expected behavior The command should be run without exception.

Environment

  • NixOS-22.11
  • commit: 0fe904a

Additional context An issue was opened recently on the bash_kernel repository with the same behavior. https://github.com/takluyver/bash_kernel/issues/121

djacu avatar Jul 26 '22 03:07 djacu

@garbas and I tried adding the bash package to the runtime packages for the bash kernel but this produces other strange errors. When a cell is run, the operation does not complete and crashes the kernel.

Traceback
Traceback (most recent call last):
  File "/nix/store/6wiycdxh63mk4krdd75db0hshicna6yy-python3-3.10.4/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/nix/store/6wiycdxh63mk4krdd75db0hshicna6yy-python3-3.10.4/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/nix/store/mwag8kp2r7z0b89xz2jq9cczh8diiwqs-python3-3.10.4-env/lib/python3.10/site-packages/bash_kernel/__main__.py", line 3, in <module>
    IPKernelApp.launch_instance(kernel_class=BashKernel)
  File "/nix/store/mwag8kp2r7z0b89xz2jq9cczh8diiwqs-python3-3.10.4-env/lib/python3.10/site-packages/traitlets/config/application.py", line 975, in launch_instance
    app.initialize(argv)
  File "/nix/store/mwag8kp2r7z0b89xz2jq9cczh8diiwqs-python3-3.10.4-env/lib/python3.10/site-packages/traitlets/config/application.py", line 110, in inner
    return method(app, *args, **kwargs)
  File "/nix/store/mwag8kp2r7z0b89xz2jq9cczh8diiwqs-python3-3.10.4-env/lib/python3.10/site-packages/ipykernel/kernelapp.py", line 681, in initialize
    self.init_kernel()
  File "/nix/store/mwag8kp2r7z0b89xz2jq9cczh8diiwqs-python3-3.10.4-env/lib/python3.10/site-packages/ipykernel/kernelapp.py", line 528, in init_kernel
    kernel = kernel_factory(
  File "/nix/store/mwag8kp2r7z0b89xz2jq9cczh8diiwqs-python3-3.10.4-env/lib/python3.10/site-packages/traitlets/config/configurable.py", line 551, in instance
    inst = cls(*args, **kwargs)
  File "/nix/store/mwag8kp2r7z0b89xz2jq9cczh8diiwqs-python3-3.10.4-env/lib/python3.10/site-packages/bash_kernel/kernel.py", line 81, in __init__
    self._start_bash()
  File "/nix/store/mwag8kp2r7z0b89xz2jq9cczh8diiwqs-python3-3.10.4-env/lib/python3.10/site-packages/bash_kernel/kernel.py", line 102, in _start_bash
    self.bashwrapper = IREPLWrapper(child, u'\$', prompt_change,
  File "/nix/store/mwag8kp2r7z0b89xz2jq9cczh8diiwqs-python3-3.10.4-env/lib/python3.10/site-packages/bash_kernel/kernel.py", line 32, in __init__
    replwrap.REPLWrapper.__init__(self, cmd_or_spawn, orig_prompt,
  File "/nix/store/mwag8kp2r7z0b89xz2jq9cczh8diiwqs-python3-3.10.4-env/lib/python3.10/site-packages/pexpect/replwrap.py", line 55, in __init__
    self._expect_prompt()
  File "/nix/store/mwag8kp2r7z0b89xz2jq9cczh8diiwqs-python3-3.10.4-env/lib/python3.10/site-packages/bash_kernel/kernel.py", line 52, in _expect_prompt
    pos = replwrap.REPLWrapper._expect_prompt(self, timeout=timeout)
  File "/nix/store/mwag8kp2r7z0b89xz2jq9cczh8diiwqs-python3-3.10.4-env/lib/python3.10/site-packages/pexpect/replwrap.py", line 65, in _expect_prompt
    return self.child.expect_exact([self.prompt, self.continuation_prompt],
  File "/nix/store/mwag8kp2r7z0b89xz2jq9cczh8diiwqs-python3-3.10.4-env/lib/python3.10/site-packages/pexpect/spawnbase.py", line 421, in expect_exact
    return exp.expect_loop(timeout)
  File "/nix/store/mwag8kp2r7z0b89xz2jq9cczh8diiwqs-python3-3.10.4-env/lib/python3.10/site-packages/pexpect/expect.py", line 181, in expect_loop
    return self.timeout(e)
  File "/nix/store/mwag8kp2r7z0b89xz2jq9cczh8diiwqs-python3-3.10.4-env/lib/python3.10/site-packages/pexpect/expect.py", line 144, in timeout
    raise exc
pexpect.exceptions.TIMEOUT: Timeout exceeded.
<pexpect.pty_spawn.spawn object at 0x7f96be976320>
command: /nix/store/qhvvivdi9pkvfpv7130sa71kpslkjv6f-bash-5.1-p16/bin/bash
args: [b'/nix/store/qhvvivdi9pkvfpv7130sa71kpslkjv6f-bash-5.1-p16/bin/bash', b'--rcfile', b'/nix/store/mwag8kp2r7z0b89xz2jq9cczh8diiwqs-python3-3.10.4-env/lib/python3.10/site-packages/pexpect/bashrc.sh']
buffer (last 100 chars): 'P\\[\\]ECT_PROMPT>'
before (last 100 chars): '[PEXP\\[\\]ECT_PROMPT>'
after: <class 'pexpect.exceptions.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 746192
child_fd: 48
closed: False
timeout: 30
delimiter: <class 'pexpect.exceptions.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
searcher: searcher_string:
    0: '[PEXPECT_PROMPT>'
    1: '[PEXPECT_PROMPT+'

As noted in the previously mentioned issues on the bash_kernel repo, you can get unexpected behaviour if PS1 or PROMPT_COMMAND has commands being run it it. I'm not certain if this is the case here, but I invoked the bash shell mentioned in the stack trace.

/nix/store/qhvvivdi9pkvfpv7130sa71kpslkjv6f-bash-5.1-p16/bin/bash

It changed my shell from this

[bakerdn@tweag-laptop:~/tweag/jupyterWith]$

to this

\[\][\[\]bakerdn@tweag-laptop:~/tweag/jupyterWith]$\[\]

djacu avatar Aug 03 '22 23:08 djacu

Also discovered that running the old kernel without bash in the runtime packages in a nix develop environment causes similar issues.

djacu avatar Aug 03 '22 23:08 djacu