nlp-with-transformers / notebooks

Jupyter notebooks for the Natural Language Processing with Transformers book
https://transformersbook.com/
Apache License 2.0
3.7k stars 1.13k forks source link

SubprocessError: Exception occurred in preexec_fn #139

Open mikechen66 opened 1 month ago

mikechen66 commented 1 month ago

Information

The problem arises in chapter:

Describe the bug

[chown Operation not permitted]

chown: changing ownership of 'elasticsearch-7.9.2/NOTICE.txt': Operation not permitted chown: changing ownership of 'elasticsearch-7.9.2/config/users_roles': Operation not permitted chown: changing ownership of 'elasticsearch-7.9.2/config/log4j2.properties': Operation not permitted

File ~/miniconda3/envs/torch/lib/python3.10/subprocess.py:1864, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session) 1862 err_msg = os.strerror(errno_num) 1863 raise child_exception_type(errno_num, err_msg, err_filename) -> 1864 raise child_exception_type(err_msg)

To Reproduce

Steps to reproduce the behavior:

  1. !chown -R daemon:daemon elasticsearch-7.9.2
  2. es_server = Popen(args=['elasticsearch-7.9.2/bin/elasticsearch'], stdout=PIPE, stderr=STDOUT, preexec_fn=lambda: os.setuid(1))

Expected behavior

mikechen66 commented 1 month ago

The following attempts failed

1. Add password

!sudo -S apt-get install blah /home/mike/Documents/transformer-notebooks/mypassword

It propmts a box for authenticating a password. After input the password,it allows it to go through the step.

!sudo chown -R daemon:daemon elasticsearch-7.9.2

It reminds me of inputing password. However, there is no a prompted box for filling the password again.

2. Try getpass function

The following command also is not useful.

import getpass
import os

password = getpass.getpass()
command = "sudo -S apt-get update" #can be any command but don't forget -S as it enables input from stdin
os.system('echo %s | %s' % (password, command))

Reference:

https://stackoverflow.com/questions/44996933/using-sudo-inside-jupyter-notebooks-cell https://stackoverflow.com/questions/77991709/exception-handling-for-subprocess-run https://askubuntu.com/questions/1380103/chown-operation-not-permitted https://github.com/jupyterhub/jupyterhub/issues/1527 https://github.com/nlp-with-transformers/notebooks/issues/139 https://jupyterhub.readthedocs.io/en/stable/howto/configuration/config-sudo.html