(message: str)
| 207 | |
| 208 | |
| 209 | def _write_to_file(message: str): |
| 210 | if _file_writing_disabled: |
| 211 | return |
| 212 | # deque.append 在 CPython 受 GIL 保护,无需额外锁 |
| 213 | if len(_log_deque) >= _MAX_QUEUE_SIZE: |
| 214 | return # 过载保护:丢弃而非阻塞 |
| 215 | _log_deque.append(message) |
| 216 | # 非阻塞通知 writer(acquire 失败直接跳过,不影响主线程) |
| 217 | if _deque_condition.acquire(blocking=False): |
| 218 | try: |
| 219 | _deque_condition.notify() |
| 220 | finally: |
| 221 | _deque_condition.release() |
| 222 | |
| 223 | |
| 224 | # ----------------------------------------------------------------- |