Update rvc_service.py
Browse files- rvc_service.py +29 -19
rvc_service.py
CHANGED
@@ -177,27 +177,37 @@ class RVCService:
|
|
177 |
"""Start the service"""
|
178 |
if not self.is_running:
|
179 |
self.is_running = True
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
logger.info("RVC Service started")
|
|
|
|
|
|
|
|
|
|
|
182 |
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
)
|
197 |
-
|
198 |
-
if self.job_queue.add_job(job):
|
199 |
-
return job_id
|
200 |
-
return None
|
201 |
|
202 |
# Memory management utilities
|
203 |
def cleanup_gpu_memory():
|
|
|
177 |
"""Start the service"""
|
178 |
if not self.is_running:
|
179 |
self.is_running = True
|
180 |
+
# Create a new event loop for the worker
|
181 |
+
loop = asyncio.new_event_loop()
|
182 |
+
asyncio.set_event_loop(loop)
|
183 |
+
|
184 |
+
# Start the worker loop in the background
|
185 |
+
def run_worker():
|
186 |
+
loop.run_until_complete(self.worker_loop())
|
187 |
+
|
188 |
+
self.worker_thread = threading.Thread(target=run_worker)
|
189 |
+
self.worker_thread.daemon = True
|
190 |
+
self.worker_thread.start()
|
191 |
logger.info("RVC Service started")
|
192 |
+
|
193 |
+
def stop(self):
|
194 |
+
"""Stop the service"""
|
195 |
+
self.is_running = False
|
196 |
+
logger.info("RVC Service stopping...")
|
197 |
|
198 |
+
async def submit_job(self, audio_data: np.ndarray, model_name: str, priority: int = 1) -> str:
|
199 |
+
"""Submit a new job to the service"""
|
200 |
+
job_id = f"job_{int(time.time())}_{id(audio_data)}"
|
201 |
+
job = JobRequest(
|
202 |
+
id=job_id,
|
203 |
+
audio_data=audio_data,
|
204 |
+
model_name=model_name,
|
205 |
+
priority=priority
|
206 |
+
)
|
207 |
+
|
208 |
+
if self.job_queue.add_job(job):
|
209 |
+
return job_id
|
210 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
211 |
|
212 |
# Memory management utilities
|
213 |
def cleanup_gpu_memory():
|