Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 02586f1

Browse files
committed
zephyr_mirror: Port sharding wrapper to asyncio.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 7831d97 commit 02586f1

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

zulip/integrations/zephyr/zephyr_mirror.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22

3+
import asyncio
34
import os
45
import signal
56
import subprocess
@@ -32,21 +33,22 @@ def die(signal: int, frame: FrameType) -> None:
3233
sys.exit(0)
3334

3435
if options.forward_class_messages and not options.noshard:
35-
# Needed to get access to zephyr.lib.parallel
36-
sys.path.append("/home/zulip/zulip")
3736
if options.on_startup_command is not None:
3837
subprocess.call([options.on_startup_command])
39-
from zerver.lib.parallel import run_parallel
4038

4139
print("Starting parallel zephyr class mirroring bot")
42-
jobs = list("0123456789abcdef")
40+
shards = list("0123456789abcdef")
4341

44-
def run_job(shard: str) -> int:
45-
subprocess.call(args + [f"--shard={shard}"])
46-
return 0
42+
async def run_shard(shard: str) -> int:
43+
process = await asyncio.create_subprocess_exec(*args, f"--shard={shard}")
44+
return await process.wait()
4745

48-
for (status, job) in run_parallel(run_job, jobs, threads=16):
49-
print("A mirroring shard died!")
46+
async def run_shards():
47+
for coro in asyncio.as_completed(map(run_shard, shards)):
48+
await coro
49+
print("A mirroring shard died!")
50+
51+
asyncio.run(run_shards())
5052
sys.exit(0)
5153

5254
backoff = RandomExponentialBackoff(timeout_success_equivalent=300)

0 commit comments

Comments
 (0)