fix(bot): 🐛 p.call and p.skip not warning about scheduled shutdown.
This commit is contained in:
@@ -3,13 +3,20 @@ from multiprocessing import managers
|
||||
from datetime import datetime, timezone
|
||||
|
||||
|
||||
def shard(shard_id: int, shard_count: int, shutdown: managers.ValueProxy[bool]) -> None:
|
||||
def shard(
|
||||
shard_id: int,
|
||||
shard_count: int,
|
||||
shutdown: managers.ValueProxy[bool],
|
||||
scheduled_shutdown: managers.ValueProxy[bool],
|
||||
) -> None:
|
||||
"""Starts a new shard.
|
||||
|
||||
Args:
|
||||
shard_id (int): The shard's ID.
|
||||
shard_count (int): The total amount of shards.
|
||||
shutdown (ValueProxy[bool]): The flag for the main process to shut down all shards.
|
||||
scheduled_shutdown (ValueProxy[bool]): The flag for other shards to know the bot's gonna
|
||||
shut down soon.
|
||||
"""
|
||||
|
||||
from payphone.bot import bot
|
||||
@@ -18,6 +25,7 @@ def shard(shard_id: int, shard_count: int, shutdown: managers.ValueProxy[bool])
|
||||
bot.shard_ids = [shard_id]
|
||||
bot.shard_count = shard_count
|
||||
bot.shutdown = shutdown
|
||||
bot.scheduled_shutdown = scheduled_shutdown
|
||||
|
||||
try:
|
||||
import uvloop # pylint: disable=import-error
|
||||
@@ -97,11 +105,12 @@ if __name__ == "__main__":
|
||||
|
||||
manager = mp.Manager()
|
||||
shutdown = manager.Value("b", False)
|
||||
scheduled_shutdown = manager.Value("b", False)
|
||||
|
||||
print(f"Starting {shard_count} shard{"s" if shard_count != 1 else ""}.")
|
||||
|
||||
ps: list[mp.Process] = [
|
||||
mp.Process(target=shard, args=(i, shard_count, shutdown))
|
||||
mp.Process(target=shard, args=(i, shard_count, shutdown, scheduled_shutdown))
|
||||
for i in range(shard_count)
|
||||
]
|
||||
flushing_p = mp.Process(target=flush_process)
|
||||
|
||||
Reference in New Issue
Block a user