Revert "Switch to os.system instead of subprocess which is not thread-safe"

This reverts commit bc28c27d75f632dbf27bc45e662a3bce8ba8cf9e.