Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0fe0199

Browse files
committed
Handle timeout for fresh process better
1 parent077b7e3 commit0fe0199

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

‎backend/main/workers/master.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def __init__(self):
2323
self.result_queue=Queue()
2424
self.awaiting_input=False
2525
self.process=None
26+
self.fresh_process=True
2627
self.start_process()
2728

2829
@atexit.register
@@ -31,6 +32,7 @@ def cleanup():
3132
self.process.terminate()
3233

3334
defstart_process(self):
35+
self.fresh_process=True
3436
self.process=Process(
3537
target=worker_loop_in_thread,
3638
args=(self.task_queue,self.input_queue,self.result_queue),
@@ -62,12 +64,11 @@ def await_result(self):
6264
def_await_result(self):
6365
# TODO cancel if result was cancelled by a newer handle_entry
6466
result=None
65-
# TODO handle initial timeout better
66-
timeout=10
6767
whileresultisNone:
68+
timeout=10ifself.fresh_processelse3
6869
try:
6970
result=self.result_queue.get(timeout=timeout)
70-
timeout=3
71+
assert (resultisNone)==self.fresh_process
7172
exceptqueue.Empty:
7273
alive=self.process.is_alive()
7374
print(f"Process{alive=}")
@@ -82,14 +83,19 @@ def _await_result(self):
8283
],
8384
output='The process died.',
8485
)
86+
self.fresh_process=False
8587
returnresult
8688

8789

8890
user_processes=defaultdict(UserProcess)
8991

9092
app=flask.Flask(__name__)
9193

92-
multiprocessing.set_start_method("spawn")
94+
try:
95+
multiprocessing.set_start_method("spawn")
96+
exceptRuntimeError:
97+
# noinspection PyArgumentList
98+
assertmultiprocessing.get_start_method()=="spawn"
9399

94100

95101
@app.route("/run",methods=["POST"])

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp