Garbage Collect Autohost subprocesses to accumulate less open file descriptors which may crash the webhost service.
This commit is contained in:
parent
8dc2a5748c
commit
c0cd79f0d7
|
@ -2,6 +2,7 @@ from __future__ import annotations
|
||||||
import logging
|
import logging
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
from datetime import timedelta, datetime
|
from datetime import timedelta, datetime
|
||||||
|
import concurrent.futures
|
||||||
import sys
|
import sys
|
||||||
import typing
|
import typing
|
||||||
import time
|
import time
|
||||||
|
@ -136,6 +137,7 @@ def autohost(config: dict):
|
||||||
|
|
||||||
multiworlds = {}
|
multiworlds = {}
|
||||||
|
|
||||||
|
guardians = concurrent.futures.ThreadPoolExecutor(2, thread_name_prefix="Guardian")
|
||||||
|
|
||||||
class MultiworldInstance():
|
class MultiworldInstance():
|
||||||
def __init__(self, room: Room, config: dict):
|
def __init__(self, room: Room, config: dict):
|
||||||
|
@ -153,12 +155,18 @@ class MultiworldInstance():
|
||||||
args=(self.room_id, self.ponyconfig),
|
args=(self.room_id, self.ponyconfig),
|
||||||
name="MultiHost")
|
name="MultiHost")
|
||||||
self.process.start()
|
self.process.start()
|
||||||
|
self.guardian = guardians.submit(self._collect)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
if self.process:
|
if self.process:
|
||||||
self.process.terminate()
|
self.process.terminate()
|
||||||
self.process = None
|
self.process = None
|
||||||
|
|
||||||
|
def _collect(self):
|
||||||
|
self.process.join() # wait for process to finish
|
||||||
|
self.process = None
|
||||||
|
self.guardian = None
|
||||||
|
|
||||||
|
|
||||||
from .models import Room, Generation, STATE_QUEUED, STATE_STARTED, STATE_ERROR, db, Seed
|
from .models import Room, Generation, STATE_QUEUED, STATE_STARTED, STATE_ERROR, db, Seed
|
||||||
from .customserver import run_server_process
|
from .customserver import run_server_process
|
||||||
|
|
Loading…
Reference in New Issue