mirror of
https://github.com/onionshare/onionshare.git
synced 2025-05-02 06:26:10 -04:00
Add cleanup method for the Meek class to kill any meek-client subprocesses once done. Hide stderr from the CLI printed output
This commit is contained in:
parent
969cd2bb62
commit
fa0f707a22
3 changed files with 43 additions and 2 deletions
|
@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
import subprocess
|
||||
import time
|
||||
from queue import Queue, Empty
|
||||
from threading import Thread
|
||||
|
||||
|
@ -86,6 +87,7 @@ class Meek(object):
|
|||
self.meek_front,
|
||||
],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
startupinfo=startupinfo,
|
||||
bufsize=1,
|
||||
env=self.meek_env,
|
||||
|
@ -101,6 +103,7 @@ class Meek(object):
|
|||
self.meek_front,
|
||||
],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
bufsize=1,
|
||||
env=self.meek_env,
|
||||
text=True,
|
||||
|
@ -136,6 +139,40 @@ class Meek(object):
|
|||
self.common.log("Meek", "start", "Could not obtain the meek port")
|
||||
raise MeekNotRunning()
|
||||
|
||||
def cleanup(self):
|
||||
"""
|
||||
Kill any meek subprocesses.
|
||||
"""
|
||||
self.common.log("Meek", "cleanup")
|
||||
|
||||
if self.meek_proc:
|
||||
self.meek_proc.terminate()
|
||||
time.sleep(0.2)
|
||||
if self.meek_proc.poll() is None:
|
||||
self.common.log(
|
||||
"Meek",
|
||||
"cleanup",
|
||||
"Tried to terminate meek-client process but it's still running",
|
||||
)
|
||||
try:
|
||||
self.meek_proc.kill()
|
||||
time.sleep(0.2)
|
||||
if self.meek_proc.poll() is None:
|
||||
self.common.log(
|
||||
"Meek",
|
||||
"cleanup",
|
||||
"Tried to kill meek-client process but it's still running",
|
||||
)
|
||||
except Exception:
|
||||
self.common.log(
|
||||
"Meek", "cleanup", "Exception while killing meek-client process"
|
||||
)
|
||||
self.meek_proc = None
|
||||
|
||||
# Reset other Meek settings
|
||||
self.meek_proxies = {}
|
||||
self.meek_port = None
|
||||
|
||||
|
||||
class MeekNotRunning(Exception):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue