Repository: thefuck
Issue: running `fuck` after successful `apt update` errors after several seconds
Labels: bug,enhancement,help wanted,hacktoberfest

<!-- If you have any issue with The Fuck, sorry about that, but we will do what we
can to fix that. Actually, maybe we already have, so first thing to do is to
update The Fuck and see if the bug is still there. -->

<!-- If it is (sorry again), check if the problem has not already been reported and
if not, just open an issue on [GitHub](https://github.com/nvbn/thefuck) with
the following basic information: -->

Correct me if I'm wrong, but shouldn't TheFuck also recognize recommended commands from the previous successful command?

Running `fuck` after successful `sudo apt update` errors and prints long stacktrace on terminal.

Expected behavior:

    either `apt list --upgradable` or `sudo apt upgrade` is recommended or `no fucks given`.

The output of `thefuck --version` (something like `The Fuck 3.1 using Python
3.5.0 and Bash 4.4.12(1)-release`):

    `The Fuck 3.30 using Python 3.8.5 and Bash 5.0.17(1)-release`

Your system (Debian 7, ArchLinux, Windows, etc.):

    Ubuntu 20.04 LTS

How to reproduce the bug:

    1. execute `sudo apt update`
    2. execute `fuck`

The output of The Fuck with `THEFUCK_DEBUG=true` exported (typically execute `export THEFUCK_DEBUG=true` in your shell before The Fuck):
```
 0  ◣ tooster@toosterLap:~$ sudo apt update
Hit:1 http://dl.google.com/linux/chrome/deb stable InRelease
Hit:2 http://pl.archive.ubuntu.com/ubuntu focal InRelease                                                                                                                                                                          
Hit:3 http://ppa.launchpad.net/appimagelauncher-team/stable/ubuntu focal InRelease                                                                                                                                                 
Hit:4 http://pl.archive.ubuntu.com/ubuntu focal-updates InRelease                                                                                                                                                                  
Hit:5 https://download.mono-project.com/repo/ubuntu stable-focal InRelease                                                                                                                                                       
Hit:6 http://pl.archive.ubuntu.com/ubuntu focal-backports InRelease                                                                                                         
Hit:7 http://ppa.launchpad.net/bashtop-monitor/bashtop/ubuntu focal InRelease                                                                    
Hit:8 http://security.ubuntu.com/ubuntu focal-security InRelease                                                           
Hit:9 http://ppa.launchpad.net/lutris-team/lutris/ubuntu focal InRelease                                                       
Ign:10 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64  InRelease        
Hit:11 https://packages.microsoft.com/ubuntu/20.04/prod focal InRelease  
Hit:12 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64  Release
Hit:13 http://ppa.launchpad.net/obsproject/obs-studio/ubuntu focal InRelease
Hit:14 http://ppa.launchpad.net/webupd8team/y-ppa-manager/ubuntu focal InRelease
Reading package lists... Done                      
Building dependency tree       
Reading state information... Done
65 packages can be upgraded. Run 'apt list --upgradable' to see them.
 0  ◣ tooster@toosterLap:~$ fuck
DEBUG: Run with settings: {'alter_history': True,
 'debug': True,
 'env': {'GIT_TRACE': '1', 'LANG': 'C', 'LC_ALL': 'C'},
 'exclude_rules': [],
 'history_limit': None,
 'instant_mode': False,
 'no_colors': False,
 'num_close_matches': 3,
 'priority': {},
 'repeat': False,
 'require_confirmation': True,
 'rules': [<const: All rules enabled>],
 'slow_commands': ['lein', 'react-native', 'gradle', './gradlew', 'vagrant'],
 'user_dir': PosixPath('/home/tooster/.config/thefuck'),
 'wait_command': 3,
 'wait_slow_command': 15}
DEBUG: Call: sudo apt update; with env: {
    'SHELL': '/bin/bash',
    'SESSION_MANAGER': 'local/toosterLap:@/tmp/.ICE-unix/2666,unix/toosterLap:/tmp/.ICE-unix/2666',
    'QT_ACCESSIBILITY': '1',
    'TF_SHELL': 'bash',
    'COLORTERM': 'truecolor',
    'XDG_CONFIG_DIRS': '/etc/xdg/xdg-ubuntu:/etc/xdg:/usr/share/kubuntu-default-settings/kf5-settings',
    'LESS': ' -R --mouse --wheel-lines=3',
    'XDG_MENU_PREFIX': 'gnome-',
    'GNOME_DESKTOP_SESSION_ID': 'this-is-deprecated',
    'LANGUAGE': 'en_GB:en',
    'LESS_TERMCAP_se': '\x1b[0m',
    'MANDATORY_PATH': '/usr/share/gconf/ubuntu.mandatory.path',
    'LESS_TERMCAP_so': '\x1b[01;7;33m',
    'LC_ADDRESS': 'pl_PL.UTF-8',
    'JAVA_HOME': '/home/tooster/.sdkman/candidates/java/current',
    'GNOME_SHELL_SESSION_MODE': 'ubuntu',
    'LC_NAME': 'pl_PL.UTF-8',
    'SSH_AUTH_SOCK': '/run/user/1000/keyring/ssh',
    'GRADLE_HOME': '/home/tooster/.sdkman/candidates/gradle/current',
    'SDKMAN_CANDIDATES_DIR': '/home/tooster/.sdkman/candidates',
    'XMODIFIERS': '@im=ibus',
    'DESKTOP_SESSION': 'ubuntu',
    'LC_MONETARY': 'pl_PL.UTF-8',
    'SSH_AGENT_PID': '2639',
    'GTK_MODULES': 'gail:atk-bridge',
    'PWD': '/home/tooster',
    'XDG_SESSION_DESKTOP': 'ubuntu',
    'LOGNAME': 'tooster',
    'XDG_SESSION_TYPE': 'x11',
    'GPG_AGENT_INFO': '/run/user/1000/gnupg/S.gpg-agent:0:1',
    'XAUTHORITY': '/run/user/1000/gdm/Xauthority',
    'GJS_DEBUG_TOPICS': 'JS ERROR;JS LOG',
    'WINDOWPATH': '2',
    'HOME': '/home/tooster',
    'USERNAME': 'tooster',
    'IM_CONFIG_PHASE': '1',
    'AUTOJUMP_ERROR_PATH': '/home/tooster/.local/share/autojump/errors.log',
    'LC_PAPER': 'pl_PL.UTF-8',
    'LANG': 'C',
    'LS_COLORS': '--cut for readibility--',
    'XDG_CURRENT_DESKTOP': 'ubuntu:GNOME',
    'VTE_VERSION': '6003',
    'SDKMAN_VERSION': '5.9.1+575',
    'GNOME_TERMINAL_SCREEN': '--redacted--',
    'INVOCATION_ID': '--redacted--',
    'MANAGERPID': '2400',
    'TF_ALIAS': 'fuck',
    'GJS_DEBUG_OUTPUT': 'stderr',
    'LESSCLOSE': '/usr/bin/lesspipe %s %s',
    'XDG_SESSION_CLASS': 'user',
    'TERM': 'xterm-256color',
    'LC_IDENTIFICATION': 'pl_PL.UTF-8',
    'LESS_TERMCAP_mb': '\x1b[1;5;32m',
    'LESS_TERMCAP_me': '\x1b[0m',
    'LESS_TERMCAP_md': '\x1b[1;32m',
    'TF_HISTORY': '\t sudo apt update\n\t sudo apt install python3-dev python3-pip python3-setuptools\n\t sudo pip3 install thefuck\n\t vim\n\t apt update\n\t sudo apt update\n\t fuck\n\t sudo apt update\n\t export THEFUCK_DEBUG=true fuck\n\t sudo apt update',
    'DEFAULTS_PATH': '/usr/share/gconf/ubuntu.default.path',
    'LESSOPEN': '| pygmentize -gO style=monokai %s',
    'LIBVIRT_DEFAULT_URI': 'qemu:///system',
    'USER': 'tooster',
    'CUDA_PATH': '/usr/local/cuda',
    'PYTHONIOENCODING': 'utf-8',
    'TF_SHELL_ALIASES': 'alias alert=\'notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e \'\\\'\'s/^\\s*[0-9]\\+\\s*//;s/[;&|]\\s*alert$//\'\\\'\')"\'\nalias aliases=\'vim ~/.bash_aliases && . ~/.bash_aliases && echo \'\\\'\'.bash_aliases sourced\'\\\'\'\'\nalias antlr4=\'java -Xmx500M -cp "/usr/local/lib/antlr-4.8-complete.jar:$CLASSPATH" org.antlr.v4.Tool\'\nalias dotfiles=\'/usr/bin/git --git-dir=$HOME/.dotfiles --work-tree=$HOME\'\nalias egrep=\'egrep --color=auto\'\nalias f=\'formatter\'\nalias fgrep=\'fgrep --color=auto\'\nalias grep=\'grep --color=auto\'\nalias grun=\'java -Xmx500M -cp "/usr/local/lib/antlr-4.8-complete.jar:$CLASSPATH" org.antlr.v4.gui.TestRig\'\nalias l=\'ls -CF\'\nalias la=\'ls -A\'\nalias lenny=\'echo "( ͡° ͜ʖ ͡°)"\'\nalias ll=\'ls -alF\'\nalias ls=\'ls --color=auto\'\nalias man=\'better_man\'\nalias notes=\'code ~/notes.md\'\nalias pip=\'pip3\'\nalias python=\'python3\'\nalias t=\'_ttr_new_tmux_session\'\nalias wp=\'cd ~/workspace\'',
    'GNOME_TERMINAL_SERVICE': ':1.101',
    'SDKMAN_DIR': '/home/tooster/.sdkman',
    'AUTOJUMP_SOURCED': '1',
    'DISPLAY': ':1',
    'LESS_TERMCAP_ue': '\x1b[0m',
    'SHLVL': '1',
    'LESS_TERMCAP_us': '\x1b[1;4;31m',
    'LC_TELEPHONE': 'pl_PL.UTF-8',
    'QT_IM_MODULE': 'ibus',
    'LC_MEASUREMENT': 'pl_PL.UTF-8',
    'SDKMAN_CANDIDATES_API': 'https://api.sdkman.io/2',
    'PAPERSIZE': 'a4',
    'CLASSPATH': '.:/usr/local/lib/antlr-4.8-complete.jar:',
    'XDG_RUNTIME_DIR': '/run/user/1000',
    'LC_TIME': 'pl_PL.UTF-8',
    'CUDA_HOME': '/usr/local/cuda',
    'JOURNAL_STREAM': '9:55039',
    'XDG_DATA_DIRS': '/usr/share/ubuntu:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop',
    'PATH': '/home/tooster/.sdkman/candidates/java/current/bin:/home/tooster/.sdkman/candidates/gradle/current/bin:/home/tooster/.gem/ruby/2.7.0/bin:/usr/local/cuda/bin:/home/tooster/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/tooster/.dotnet/tools',
    'GDMSESSION': 'ubuntu',
    'THEFUCK_DEBUG': 'true',
    'DBUS_SESSION_BUS_ADDRESS': 'unix:path=/run/user/1000/bus',
    'SDKMAN_PLATFORM': 'Linux64',
    'LC_NUMERIC': 'pl_PL.UTF-8',
    '_': '/usr/local/bin/thefuck',
    'LC_ALL': 'C',
    'GIT_TRACE': '1'
}; is slow: False took: 0:00:03.052979
DEBUG: Total took: 0:00:03.082849
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/thefuck/output_readers/rerun.py", line 35, in _wait_output
    proc.wait(settings.wait_slow_command if is_slow
  File "/home/tooster/.local/lib/python3.8/site-packages/psutil/__init__.py", line 1259, in wait
    self._exitcode = self._proc.wait(timeout)
  File "/home/tooster/.local/lib/python3.8/site-packages/psutil/_pslinux.py", line 1517, in wrapper
    return fun(self, *args, **kwargs)
  File "/home/tooster/.local/lib/python3.8/site-packages/psutil/_pslinux.py", line 1725, in wait
    return _psposix.wait_pid(self.pid, timeout, self._name)
  File "/home/tooster/.local/lib/python3.8/site-packages/psutil/_psposix.py", line 131, in wait_pid
    interval = sleep(interval)
  File "/home/tooster/.local/lib/python3.8/site-packages/psutil/_psposix.py", line 108, in sleep
    raise TimeoutExpired(timeout, pid=pid, name=proc_name)
psutil.TimeoutExpired: psutil.TimeoutExpired timeout after 3 seconds (pid=63423)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tooster/.local/lib/python3.8/site-packages/psutil/__init__.py", line 1174, in _send_signal
    os.kill(self.pid, sig)
PermissionError: [Errno 1] Operation not permitted

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/thefuck/output_readers/rerun.py", line 17, in _kill_process
    proc.kill()
  File "/home/tooster/.local/lib/python3.8/site-packages/psutil/__init__.py", line 270, in wrapper
    return fun(self, *args, **kwargs)
  File "/home/tooster/.local/lib/python3.8/site-packages/psutil/__init__.py", line 1237, in kill
    self._send_signal(signal.SIGKILL)
  File "/home/tooster/.local/lib/python3.8/site-packages/psutil/__init__.py", line 1184, in _send_signal
    raise AccessDenied(self.pid, self._name)
psutil.AccessDenied: psutil.AccessDenied (pid=63424)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tooster/.local/lib/python3.8/site-packages/psutil/_pslinux.py", line 1620, in exe
    return readlink("%s/%s/exe" % (self._procfs_path, self.pid))
  File "/home/tooster/.local/lib/python3.8/site-packages/psutil/_pslinux.py", line 212, in readlink
    path = os.readlink(path)
PermissionError: [Errno 13] Permission denied: '/proc/63424/exe'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/thefuck", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/thefuck/entrypoints/main.py", line 31, in main
    fix_command(known_args)
  File "/usr/local/lib/python3.8/dist-packages/thefuck/entrypoints/fix_command.py", line 36, in fix_command
    command = types.Command.from_raw_script(raw_command)
  File "/usr/local/lib/python3.8/dist-packages/thefuck/types.py", line 82, in from_raw_script
    output = get_output(script, expanded)
  File "/usr/local/lib/python3.8/dist-packages/thefuck/output_readers/__init__.py", line 20, in get_output
    return rerun.get_output(script, expanded)
  File "/usr/local/lib/python3.8/dist-packages/thefuck/output_readers/rerun.py", line 62, in get_output
    if _wait_output(result, is_slow):
  File "/usr/local/lib/python3.8/dist-packages/thefuck/output_readers/rerun.py", line 40, in _wait_output
    _kill_process(child)
  File "/usr/local/lib/python3.8/dist-packages/thefuck/output_readers/rerun.py", line 20, in _kill_process
    proc.pid, proc.exe()))
  File "/home/tooster/.local/lib/python3.8/site-packages/psutil/__init__.py", line 660, in exe
    return guess_it(fallback=err)
  File "/home/tooster/.local/lib/python3.8/site-packages/psutil/__init__.py", line 653, in guess_it
    raise fallback
  File "/home/tooster/.local/lib/python3.8/site-packages/psutil/__init__.py", line 658, in exe
    exe = self._proc.exe()
  File "/home/tooster/.local/lib/python3.8/site-packages/psutil/_pslinux.py", line 1633, in exe
    raise AccessDenied(self.pid, self._name)
psutil.AccessDenied: psutil.AccessDenied (pid=63424)

```

<!-- It's only with enough information that we can do something to fix the problem. -->