From 83cd31878c68c513c7cbef6b671e7e258310bc35 Mon Sep 17 00:00:00 2001 From: Mikei386 <44135113+Mikei386@users.noreply.github.com> Date: Mon, 5 Oct 2026 11:49:56 +0200 Subject: [PATCH] Load native Applio source in resident inference worker --- applio_worker.py | 3 +++ test_applio.py | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/applio_worker.py b/applio_worker.py index 955f6b7..419c12c 100644 --- a/applio_worker.py +++ b/applio_worker.py @@ -11,6 +11,9 @@ def main(): bind_parent() if len(sys.argv)>1 and sys.argv[1]=="--exec": os.execv(sys.argv[2],sys.argv[2:]) + # A script launched from /app does not add its runtime working directory + # to Python's import path. RVC lives in the separately installed source tree. + sys.path.insert(0,os.environ.get('APPLIO_WORKDIR',os.getcwd())) with contextlib.redirect_stdout(sys.stderr): from rvc.infer.infer import VoiceConverter converter=VoiceConverter() diff --git a/test_applio.py b/test_applio.py index edb247a..18615eb 100644 --- a/test_applio.py +++ b/test_applio.py @@ -1,4 +1,4 @@ -import json,socket,tempfile,time,unittest +import json,os,socket,subprocess,sys,tempfile,time,unittest from pathlib import Path from types import SimpleNamespace from unittest.mock import patch @@ -47,4 +47,12 @@ class Tests(unittest.TestCase): self.assertFalse(applio_model(dict(kind='voice',file='voice.pth'))) result=assess(self.profile['model'],{'applio':True}) self.assertEqual(result['setup_steps'][1]['state'],'complete');self.assertEqual(result['components'],[]) +class WorkerTests(unittest.TestCase): + def test_worker_imports_separate_runtime_and_serves_repeated_requests(self): + with tempfile.TemporaryDirectory() as directory: + root=Path(directory);module=root/'rvc/infer';module.mkdir(parents=True) + (root/'rvc/__init__.py').write_text('');(module/'__init__.py').write_text('') + (module/'infer.py').write_text('class VoiceConverter:\n def convert_audio(self,**kwargs): pass\n') + result=subprocess.run([sys.executable,str(Path(__file__).with_name('applio_worker.py'))],input='{}\n{}\n',text=True,capture_output=True,cwd='/',env=dict(os.environ,APPLIO_WORKDIR=str(root)),timeout=10,check=True) + self.assertEqual([json.loads(line) for line in result.stdout.splitlines()],[{'ready':True},{'ok':True},{'ok':True}]) if __name__=='__main__':unittest.main()