Skip to content

Commit da4f24e

Browse files
committed
update
1 parent 8b7b212 commit da4f24e

File tree

5 files changed

+31
-46
lines changed

5 files changed

+31
-46
lines changed

QuickProject/__init__.py

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -96,65 +96,50 @@ def external_exec(
9696
:param __no_wait: ⚠️是否不等待, 这意味着需要手动获取返回值和输出
9797
:return: status code, output | __no_wait 为 True 时返回进程对象
9898
"""
99-
from rich.markdown import Markdown
99+
if __expose:
100+
from rich.markdown import Markdown
100101
from subprocess import Popen, PIPE
101-
from concurrent.futures import ThreadPoolExecutor, wait
102-
103-
class MixContent:
104-
def __init__(self):
105-
self.content = ""
106-
107-
def __add__(self, other):
108-
self.content += other
109-
return self
110-
111-
def __str__(self):
112-
return self.content
113-
114-
content = MixContent()
115-
116-
def _output(pipe_name: str, process: Popen, content: MixContent):
117-
ignore_status = (
118-
without_stdout if pipe_name == "stdout" else without_stderr
119-
) or without_output
120-
for line in iter(eval(f"process.{pipe_name}.readline"), ""):
121-
if not __expose and (
122-
line.startswith("__START__")
123-
or line.startswith("__STOP__")
124-
or line.startswith("__SPLIT__")
125-
):
102+
import concurrent.futures
103+
104+
def _output(pipe, content, ignore_status):
105+
for line in iter(pipe.readline, ""):
106+
if not __expose and line.startswith((
107+
"__START__", "__STOP__",
108+
"__TITLE__", "__RULE__")):
126109
continue
127-
content += line
110+
content.append(line)
128111
if ignore_status:
129112
continue
130113
line = line.strip()
131114
if line.startswith("__START__"):
132-
QproDefaultStatus(line.replace("__START__", "")).start()
115+
QproDefaultStatus(line.replace("__START__", "").strip()).start()
133116
elif line.startswith("__STOP__"):
134117
QproDefaultStatus.stop()
135-
elif line.startswith("__SPLIT__"):
136-
QproDefaultConsole.print(
137-
Markdown("# " + line.replace("__SPLIT__", "").strip())
138-
)
118+
elif line.startswith("__TITLE__"):
119+
QproDefaultConsole.print(Markdown("# " + line.replace("__TITLE__", "").strip()))
120+
elif line.startswith("__RULE__"):
121+
QproDefaultConsole.rule(line.replace("__RULE__", "").strip())
139122
else:
140123
QproDefaultConsole.print(line)
141124

142-
pool = ThreadPoolExecutor(2)
143-
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, bufsize=1, encoding="utf-8")
125+
output_content = []
126+
process = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, bufsize=1, encoding="utf-8")
144127

145-
if __no_wait:
146-
return p
128+
if __no_wait or without_output:
129+
return process
147130

148-
wait(
149-
[
150-
pool.submit(_output, "stdout", p, content),
151-
pool.submit(_output, "stderr", p, content),
152-
]
153-
)
154-
pool.shutdown()
155-
ret_code = p.wait()
131+
with concurrent.futures.ThreadPoolExecutor(2) as executor:
132+
futures = []
133+
if not without_stdout:
134+
futures.append(executor.submit(_output, process.stdout, output_content, without_output))
135+
if not without_stderr:
136+
futures.append(executor.submit(_output, process.stderr, output_content, without_output))
137+
concurrent.futures.wait(futures)
156138

157-
return ret_code, str(content)
139+
ret_code = process.wait()
140+
process.stdout.close()
141+
process.stderr.close()
142+
return ret_code, ''.join(output_content)
158143

159144

160145
def requirePackage(

dist/qpro-0.12.10.tar.gz

-26.6 KB
Binary file not shown.

dist/qpro-0.12.11.tar.gz

26.2 KB
Binary file not shown.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "qpro"
3-
version = "0.12.10"
3+
version = "0.12.11"
44
description = "Small but powerful command line APP framework"
55
authors = ["Rhythmicc <rhythmlian.cn@gmail.com>"]
66
license = "MIT"

0 commit comments

Comments
 (0)