aboutsummaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorMicah Lee <micah@micahflee.com>2021-12-20 12:13:21 -0800
committerGitHub <noreply@github.com>2021-12-20 12:13:21 -0800
commit4ab5e0003c83853476ae68b06ba936c8792dc362 (patch)
treec821721279dab2ea88bba4d55727618f179509a9 /cli
parentb949234e492514b5da4209214ff2e3df506e8b81 (diff)
parent2689f35635abdf8e6d17b9a0a7709a4b5f9cb182 (diff)
downloadonionshare-4ab5e0003c83853476ae68b06ba936c8792dc362.tar.gz
onionshare-4ab5e0003c83853476ae68b06ba936c8792dc362.zip
Merge pull request #1489 from mig5/meek_stdout_cleanup_fix
Don't enqueue stdout from Meek subprocess in a Thread
Diffstat (limited to 'cli')
-rw-r--r--cli/onionshare_cli/meek.py52
1 files changed, 15 insertions, 37 deletions
diff --git a/cli/onionshare_cli/meek.py b/cli/onionshare_cli/meek.py
index dffbad83..3ada19c7 100644
--- a/cli/onionshare_cli/meek.py
+++ b/cli/onionshare_cli/meek.py
@@ -20,8 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import subprocess
import time
-from queue import Queue, Empty
-from threading import Thread
class Meek(object):
@@ -67,14 +65,6 @@ class Meek(object):
Start the Meek Client and populate the SOCKS proxies dict
for use with requests to the Tor Moat API.
"""
- # Small method to read stdout from the subprocess.
- # We use this to obtain the random port that Meek
- # started on
- def enqueue_output(out, queue):
- for line in iter(out.readline, b""):
- queue.put(line)
- out.close()
-
# Abort early if we can't find the Meek client
if self.meek_client_file_path is None or not os.path.exists(
self.meek_client_file_path
@@ -124,34 +114,22 @@ class Meek(object):
universal_newlines=True,
)
- # Queue up the stdout from the subprocess for polling later
- q = Queue()
- t = Thread(target=enqueue_output, args=(self.meek_proc.stdout, q))
- t.daemon = True # thread dies with the program
- t.start()
-
- while True:
- # read stdout without blocking
- try:
- line = q.get_nowait()
- self.common.log("Meek", "start", line.strip())
- except Empty:
- # no stdout yet?
- pass
- else: # we got stdout
- if "CMETHOD meek socks5" in line:
- self.meek_host = line.split(" ")[3].split(":")[0]
- self.meek_port = line.split(" ")[3].split(":")[1]
- self.common.log(
- "Meek",
- "start",
- f"Meek running on {self.meek_host}:{self.meek_port}",
- )
- break
+ # Obtain the host and port that meek is running on
+ for line in iter(self.meek_proc.stdout.readline, b""):
+ if "CMETHOD meek socks5" in line:
+ self.meek_host = line.split(" ")[3].split(":")[0]
+ self.meek_port = line.split(" ")[3].split(":")[1]
+ self.common.log(
+ "Meek",
+ "start",
+ f"Meek running on {self.meek_host}:{self.meek_port}",
+ )
+ break
- if "CMETHOD-ERROR" in line:
- self.cleanup()
- raise MeekNotRunning()
+ if "CMETHOD-ERROR" in line:
+ self.cleanup()
+ raise MeekNotRunning()
+ break
if self.meek_port:
self.meek_proxies = {