aboutsummaryrefslogtreecommitdiff
path: root/cli/onionshare_cli/meek.py
diff options
context:
space:
mode:
authorMiguel Jacq <mig@mig5.net>2021-10-25 10:44:38 +1100
committerMiguel Jacq <mig@mig5.net>2021-10-25 10:44:38 +1100
commit3a715346af241707c952ff446734f8c7bfccd21f (patch)
tree867e24abf548502fe9f4fc0f500a7459ecd5f6ec /cli/onionshare_cli/meek.py
parentc81862130ba0969228fa61a3aaf9612ff8424971 (diff)
downloadonionshare-3a715346af241707c952ff446734f8c7bfccd21f.tar.gz
onionshare-3a715346af241707c952ff446734f8c7bfccd21f.zip
Add cleanup method for the Meek class to kill any meek-client subprocesses once done. Hide stderr from the CLI printed output
Diffstat (limited to 'cli/onionshare_cli/meek.py')
-rw-r--r--cli/onionshare_cli/meek.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/cli/onionshare_cli/meek.py b/cli/onionshare_cli/meek.py
index 482deedd..675402d3 100644
--- a/cli/onionshare_cli/meek.py
+++ b/cli/onionshare_cli/meek.py
@@ -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):
"""