jupyter / jupyter_console

Jupyter Terminal Console

Home Page:http://jupyter-console.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Operation not permitted when piping in stdin

hroncok opened this issue · comments

I wanted to write a simple smoke test for ilua, but this is where I ended up:

$ jupyter-console << EOF
> print("a")
> EOF
Warning: Input is not to a terminal (fd=0).
Jupyter console 6.1.0

Python 3.8.2 (default, Feb 28 2020, 00:00:00) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.12.0 -- An enhanced Interactive Python. Type '?' for help.

Traceback (most recent call last):
  File "/usr/bin/jupyter-console", line 11, in <module>
    load_entry_point('jupyter-console==6.1.0', 'console_scripts', 'jupyter-console')()
  File "/usr/lib/python3.8/site-packages/jupyter_core/application.py", line 268, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/usr/lib/python3.8/site-packages/traitlets/config/application.py", line 664, in launch_instance
    app.start()
  File "/usr/lib/python3.8/site-packages/jupyter_console/app.py", line 156, in start
    self.shell.mainloop()
  File "/usr/lib/python3.8/site-packages/jupyter_console/ptshell.py", line 547, in mainloop
    self.interact()
  File "/usr/lib/python3.8/site-packages/jupyter_console/ptshell.py", line 531, in interact
    code = self.prompt_for_code()
  File "/usr/lib/python3.8/site-packages/jupyter_console/ptshell.py", line 474, in prompt_for_code
    text = self.pt_cli.prompt(
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/shortcuts/prompt.py", line 797, in prompt
    return run_sync()
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/shortcuts/prompt.py", line 786, in run_sync
    return self.app.run(inputhook=self.inputhook, pre_run=pre_run2)
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 736, in run
    return run()
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 710, in run
    return f.result()
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/eventloop/future.py", line 151, in result
    raise self._exception
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/eventloop/coroutine.py", line 92, in step_next
    new_f = coroutine.throw(exc)
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 685, in _run_async2
    result = yield f
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/eventloop/coroutine.py", line 88, in step_next
    new_f = coroutine.send(None)
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 625, in _run_async
    with self.input.attach(read_from_input):
  File "/usr/lib64/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/input/vt100.py", line 150, in _attached_input
    loop.add_reader(fd, callback)
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/eventloop/posix.py", line 273, in add_reader
    self.selector.register(fd)
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/eventloop/select.py", line 78, in register
    sel.register(fd)
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/eventloop/select.py", line 133, in register
    self._sel.register(fd, selectors.EVENT_READ, None)
  File "/usr/lib64/python3.8/selectors.py", line 359, in register
    self._selector.register(key.fd, poller_events)
PermissionError: [Errno 1] Operation not permitted
$ [IPKernelApp] WARNING | Parent appears to have exited, shutting down.

Is this expected? Is there a way to pipe in some input for testing purposes? Thanks.

Warning: Input is not to a terminal (fd=0).

Maybe this hints that your input should emulate a tty?

Maybe. No idea how.

Have you tried jupyter console --simple-prompt, I think it should bypass prompt toolkit.

Slightly better, but still pretty bad:

$ jupyter-console --simple-prompt << EOF
> print("a")
> EOF
Jupyter console 6.1.0

Python 3.8.5 (default, Aug 12 2020, 00:00:00) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.12.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: ^C^C^C^C^C^\Aborted

hum, yeah I'll have to look into the Ctrl^C.
For testing can you inject a exit() instead of Ctrl^C of whatver equivalent to ilua ?

For reasons beyond me, piping the commands actually work:

$ echo 'exit()' | jupyter-console 
Warning: Input is not a terminal (fd=0).
Jupyter console 6.4.0

Python 3.9.6 (default, Jun 29 2021, 00:00:00) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.18.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: exit()                                                                                                                                                                                                                   
Shutting down kernel