Sudo prompts for a password, but IPython doesn't notice that this is happening, and you will get a hang while sudo waits.
One way to deal with this is to read your password once, and pass that to sudo with:
echo PASSWORD | sudo -S ...
BE CAREFUL with this approach, as the password is a global variable,
so may be displayed when using things like %whos
or locals()
.
from getpass import getpass
PASS = getpass('sudo password: ')
sudo password: ········
!whoami
benjaminrk
!echo $PASS | sudo -S sh -c 'whoami'
root