(stdout_file, pid, persistent_lock)
| 188 | return HttpResponseServerError(f"Error preparing stream: {e}") |
| 189 | |
| 190 | def stream_generator(stdout_file, pid, persistent_lock): |
| 191 | try: |
| 192 | while True: |
| 193 | chunk = stdout_file.read(8192) |
| 194 | if not chunk: |
| 195 | break |
| 196 | yield chunk |
| 197 | finally: |
| 198 | try: |
| 199 | os.kill(pid, signal.SIGTERM) |
| 200 | logger.debug("Streaming process terminated for channel ID=%s", channel.id) |
| 201 | except OSError: |
| 202 | pass |
| 203 | try: |
| 204 | os.waitpid(pid, os.WNOHANG) |
| 205 | except ChildProcessError: |
| 206 | pass |
| 207 | stdout_file.close() |
| 208 | persistent_lock.release() |
| 209 | logger.debug("Persistent lock released for channel ID=%s", channel.id) |
| 210 | |
| 211 | return StreamingHttpResponse( |
| 212 | stream_generator(proc_stdout, proc_pid, persistent_lock), |
no test coverage detected