thecollabagepatch commited on
Commit
1889c0a
·
1 Parent(s): cd609af

jam/stop fix

Browse files
Files changed (2) hide show
  1. app.py +6 -1
  2. jam_worker.py +5 -5
app.py CHANGED
@@ -339,8 +339,13 @@ def jam_stop(session_id: str = Body(..., embed=True)):
339
  worker = jam_registry.get(session_id)
340
  if worker is None:
341
  raise HTTPException(status_code=404, detail="Session not found")
 
342
  worker.stop()
343
- worker.join(timeout=2.0)
 
 
 
 
344
  with jam_lock:
345
  jam_registry.pop(session_id, None)
346
  return {"stopped": True}
 
339
  worker = jam_registry.get(session_id)
340
  if worker is None:
341
  raise HTTPException(status_code=404, detail="Session not found")
342
+
343
  worker.stop()
344
+ worker.join(timeout=5.0)
345
+ if worker.is_alive():
346
+ # It’s daemon=True, so it won’t block process exit, but report it
347
+ print(f"⚠️ JamWorker {session_id} did not stop within timeout")
348
+
349
  with jam_lock:
350
  jam_registry.pop(session_id, None)
351
  return {"stopped": True}
jam_worker.py CHANGED
@@ -41,13 +41,13 @@ class JamWorker(threading.Thread):
41
  self.state = mrt.init_state()
42
  self.idx = 0
43
  self.outbox: list[JamChunk] = []
44
- self._stop = threading.Event()
45
  self.last_chunk_started_at = None
46
  self.last_chunk_completed_at = None
47
  self._lock = threading.Lock()
48
 
49
  def stop(self):
50
- self._stop.set()
51
 
52
  def update_style(self, new_style_vec: np.ndarray | None):
53
  with self._lock:
@@ -90,7 +90,7 @@ class JamWorker(threading.Thread):
90
 
91
  # Prime: set initial context on state (caller should have done this; safe to re-set here)
92
  # NOTE: We assume caller passed a style_vec computed from tail/whole/blend.
93
- while not self._stop.is_set():
94
  # honor live knob updates atomically
95
  with self._lock:
96
  style_vec = self.params.style_vec
@@ -103,13 +103,13 @@ class JamWorker(threading.Thread):
103
  need = chunk_secs
104
  chunks = []
105
  self.last_chunk_started_at = time.time()
106
- while need > 0 and not self._stop.is_set():
107
  wav, self.state = self.mrt.generate_chunk(state=self.state, style=style_vec)
108
  chunks.append(wav)
109
  # model chunk length (seconds) at model SR
110
  need -= (wav.samples.shape[0] / float(self.mrt.sample_rate))
111
 
112
- if self._stop.is_set():
113
  break
114
 
115
  # 2) stitch and trim to exact seconds at model SR
 
41
  self.state = mrt.init_state()
42
  self.idx = 0
43
  self.outbox: list[JamChunk] = []
44
+ self._stop_event = threading.Event()
45
  self.last_chunk_started_at = None
46
  self.last_chunk_completed_at = None
47
  self._lock = threading.Lock()
48
 
49
  def stop(self):
50
+ self._stop_event.set()
51
 
52
  def update_style(self, new_style_vec: np.ndarray | None):
53
  with self._lock:
 
90
 
91
  # Prime: set initial context on state (caller should have done this; safe to re-set here)
92
  # NOTE: We assume caller passed a style_vec computed from tail/whole/blend.
93
+ while not self._stop_event.is_set():
94
  # honor live knob updates atomically
95
  with self._lock:
96
  style_vec = self.params.style_vec
 
103
  need = chunk_secs
104
  chunks = []
105
  self.last_chunk_started_at = time.time()
106
+ while need > 0 and not self._stop_event.is_set():
107
  wav, self.state = self.mrt.generate_chunk(state=self.state, style=style_vec)
108
  chunks.append(wav)
109
  # model chunk length (seconds) at model SR
110
  need -= (wav.samples.shape[0] / float(self.mrt.sample_rate))
111
 
112
+ if self._stop_event.is_set():
113
  break
114
 
115
  # 2) stitch and trim to exact seconds at model SR