Kill tor and its subprocesses

Author: micahfleeCreated Jan 18, 2018Updated May 9, 2025
Labelsbugminor

When using Bundled Tor, obfs4proxy, if you switch to using no bridges, it crashes like this:

[Jan 17 2018 18:32:02] SettingsDialog.save_clicked: Connected to Tor
[Jan 17 2018 18:32:02] SettingsDialog.save_clicked: rebooting the Onion
[Jan 17 2018 18:32:02] Onion.cleanup
Traceback (most recent call last):
  File "onionshare_gui\settings_dialog.py", line 628, in save_clicked
    self.onion.cleanup()
  File "onionshare\onion.py", line 511, in cleanup
    self.tor_data_directory.cleanup()
  File "tempfile.py", line 811, in cleanup
  File "shutil.py", line 494, in rmtree
  File "shutil.py", line 389, in _rmtree_unsafe
  File "shutil.py", line 387, in _rmtree_unsafe
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\MICAHL~1\\AppData\\Local\\Temp\\tmpv011cdr9\\lock'

This is because it can't delete the temporary tor data dir, and I'm pretty sure it's because obfs4proxy.exe is running and has an open file in that dir, and it doesn't get killed when tor.exe gets killed.

So I think the solution is to kill tor's children before killing the tor process (brutal, I know).