|
| 1 | +import os |
| 2 | +from pathlib import Path |
| 3 | +import sys |
| 4 | + |
| 5 | + |
| 6 | +def setup_logging() -> None: |
| 7 | + """Set up logging to both console and file""" |
| 8 | + |
| 9 | + pid = os.getpid() |
| 10 | + |
| 11 | + cache_dir = os.environ.get("CACHE_DIR") |
| 12 | + if cache_dir is None: |
| 13 | + cache_dir = Path.home() / ".dweam" / "cache" |
| 14 | + else: |
| 15 | + cache_dir = Path(cache_dir) |
| 16 | + |
| 17 | + log_dir = cache_dir / "worker_logs" |
| 18 | + log_dir.mkdir(exist_ok=True) |
| 19 | + |
| 20 | + log_file = log_dir / f"game_process_{pid}.log" |
| 21 | + |
| 22 | + # Create file handle with line buffering |
| 23 | + log_handle = open(log_file, 'w', buffering=1) |
| 24 | + |
| 25 | + # Save original stdout/stderr |
| 26 | + original_stdout = sys.stdout |
| 27 | + original_stderr = sys.stderr |
| 28 | + |
| 29 | + class DualOutput: |
| 30 | + def __init__(self, file1, file2): |
| 31 | + self.file1 = file1 |
| 32 | + self.file2 = file2 |
| 33 | + |
| 34 | + def write(self, data): |
| 35 | + self.file1.write(data) |
| 36 | + self.file2.write(data) |
| 37 | + self.file1.flush() |
| 38 | + self.file2.flush() |
| 39 | + |
| 40 | + def flush(self): |
| 41 | + self.file1.flush() |
| 42 | + self.file2.flush() |
| 43 | + |
| 44 | + # Replace stdout/stderr with dual-output versions |
| 45 | + sys.stdout = DualOutput(original_stdout, log_handle) |
| 46 | + sys.stderr = DualOutput(original_stderr, log_handle) |
| 47 | + |
| 48 | + print(f"=== Game Process {pid} Starting ===") |
| 49 | + print(f"Logging to {log_file}") |
| 50 | + print(f"Command line args: {sys.argv}") |
| 51 | + |
| 52 | + |
| 53 | +setup_logging() |
| 54 | + |
| 55 | + |
1 | 56 | import logging |
2 | 57 | logging.getLogger("aioice.ice").disabled = True |
3 | 58 |
|
4 | 59 | import asyncio |
5 | 60 | import json |
6 | | -import sys |
7 | 61 | from typing import Any |
8 | 62 | from datetime import datetime, timedelta |
9 | 63 | from dweam.constants import JS_TO_PYGAME_BUTTON_MAP, JS_TO_PYGAME_KEY_MAP |
|
15 | 69 | from aiortc import VideoStreamTrack, RTCPeerConnection, RTCSessionDescription, RTCConfiguration, RTCIceServer, RTCDataChannel |
16 | 70 | from aiortc.contrib.signaling import object_from_string, object_to_string |
17 | 71 | import torch |
18 | | -import os |
19 | 72 | import socket |
20 | 73 | from dweam.utils.process import patch_subprocess_popen |
21 | 74 |
|
|
0 commit comments