VirtualDesktop 1.6.1__tar.gz → 1.6.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/PKG-INFO +2 -1
  2. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/README.md +1 -0
  3. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/__init__.py +1 -1
  4. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/record.py +16 -3
  5. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop.egg-info/PKG-INFO +2 -1
  6. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/pyproject.toml +1 -1
  7. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_record.py +54 -0
  8. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/LICENSE +0 -0
  9. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/__main__.py +0 -0
  10. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/_bundle.py +0 -0
  11. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/_compat.py +0 -0
  12. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/_desktop_runtime.py +0 -0
  13. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/_devices.py +0 -0
  14. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/_download.py +0 -0
  15. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/_enumerate.py +0 -0
  16. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/_helper.py +0 -0
  17. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/_log.py +0 -0
  18. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/_process.py +0 -0
  19. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/_sigcheck.ps1 +0 -0
  20. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/_sigcheck.py +0 -0
  21. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/_winapi.py +0 -0
  22. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/agent.py +0 -0
  23. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/capture.py +0 -0
  24. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/cli.py +0 -0
  25. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/config.py +0 -0
  26. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/desktop.py +0 -0
  27. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/desktop_capture.py +0 -0
  28. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/desktop_session.py +0 -0
  29. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/display_setup.py +0 -0
  30. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/driver.py +0 -0
  31. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/driver_manifest.json +0 -0
  32. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/errors.py +0 -0
  33. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/manifest.py +0 -0
  34. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/session.py +0 -0
  35. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/window.py +0 -0
  36. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop/workspace.py +0 -0
  37. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop.egg-info/SOURCES.txt +0 -0
  38. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop.egg-info/dependency_links.txt +0 -0
  39. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop.egg-info/entry_points.txt +0 -0
  40. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop.egg-info/requires.txt +0 -0
  41. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/VirtualDesktop.egg-info/top_level.txt +0 -0
  42. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/setup.cfg +0 -0
  43. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_accelerators.py +0 -0
  44. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_agent.py +0 -0
  45. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_artifact_regression.py +0 -0
  46. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_capture.py +0 -0
  47. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_cli.py +0 -0
  48. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_compat.py +0 -0
  49. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_config_and_winapi.py +0 -0
  50. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_desktop_isolation.py +0 -0
  51. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_destructive_lifecycle.py +0 -0
  52. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_display_setup.py +0 -0
  53. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_download.py +0 -0
  54. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_driver.py +0 -0
  55. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_hide_modes.py +0 -0
  56. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_integration_windows.py +0 -0
  57. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_manifest.py +0 -0
  58. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_no_dialogs.py +0 -0
  59. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_packaging.py +0 -0
  60. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_process.py +0 -0
  61. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_virtual_desktop.py +0 -0
  62. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_workspace.py +0 -0
  63. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_workspace_instances.py +0 -0
  64. {virtualdesktop-1.6.1 → virtualdesktop-1.6.2}/tests/test_workspace_move.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: VirtualDesktop
3
- Version: 1.6.1
3
+ Version: 1.6.2
4
4
  Summary: win10-win11 虚拟桌面
5
5
  Author: VirtualDesktop contributors
6
6
  License: MIT License
@@ -575,6 +575,7 @@ with space.record_stream("run.gif", target=window, fps=8, duration=5) as stream:
575
575
  | `fps` | 目标帧率(必填,默认 10)。低于目标会被丢弃并计入 `report().dropped` |
576
576
  | `duration` | 秒;到点自动停止,`stopped_by="duration"` |
577
577
  | `max_frames` | 帧数上限;到点自动停止,`stopped_by="max_frames"` |
578
+ | — | 不传 `duration` 时有一个 **1 小时硬上限**(`MAX_DURATION`):录制线程持有 `Recorder` 引用,被丢弃且未 `stop()` 的对象无法回收,没有上限就会一直录下去(并带着 ffmpeg 子进程)。正常用法请始终用 `with` |
578
579
  | `quality` | 见上方格式表;不同后端含义不同 |
579
580
  | `format` | 覆盖扩展名推断 |
580
581
  | `on_frame` | `(frame, index)` 回调,每帧一次;回调抛异常不会中断录制 |
@@ -518,6 +518,7 @@ with space.record_stream("run.gif", target=window, fps=8, duration=5) as stream:
518
518
  | `fps` | 目标帧率(必填,默认 10)。低于目标会被丢弃并计入 `report().dropped` |
519
519
  | `duration` | 秒;到点自动停止,`stopped_by="duration"` |
520
520
  | `max_frames` | 帧数上限;到点自动停止,`stopped_by="max_frames"` |
521
+ | — | 不传 `duration` 时有一个 **1 小时硬上限**(`MAX_DURATION`):录制线程持有 `Recorder` 引用,被丢弃且未 `stop()` 的对象无法回收,没有上限就会一直录下去(并带着 ffmpeg 子进程)。正常用法请始终用 `with` |
521
522
  | `quality` | 见上方格式表;不同后端含义不同 |
522
523
  | `format` | 覆盖扩展名推断 |
523
524
  | `on_frame` | `(frame, index)` 回调,每帧一次;回调抛异常不会中断录制 |
@@ -72,7 +72,7 @@ from .record import (
72
72
  supported_formats,
73
73
  )
74
74
 
75
- __version__ = "1.6.1"
75
+ __version__ = "1.6.2"
76
76
 
77
77
  __all__ = [
78
78
  "__version__",
@@ -59,6 +59,7 @@ log = get_logger("record")
59
59
  __all__ = [
60
60
  "GIF_FORMATS",
61
61
  "IMAGE_FORMATS",
62
+ "MAX_DURATION",
62
63
  "Recorder",
63
64
  "RecordingReport",
64
65
  "VIDEO_FORMATS",
@@ -78,6 +79,13 @@ IMAGE_FORMATS = (".png", ".jpg", ".jpeg", ".webp", ".bmp", ".tif", ".tiff")
78
79
  #: Frames are passed to ffmpeg as PNG, which is lossless and avoids a second generation of loss.
79
80
  _PIPE_PIXEL_FORMAT = "rgb24"
80
81
 
82
+ #: Hard ceiling on a single recording, in seconds, used when the caller gives no ``duration``.
83
+ #: It exists so an abandoned recorder cannot capture forever: the capture thread holds a reference
84
+ #: to its ``Recorder``, so one that is dropped without ``stop()`` is never collected and would
85
+ #: otherwise keep its ffmpeg child alive indefinitely. Callers that want a longer recording pass an
86
+ #: explicit larger ``duration``.
87
+ MAX_DURATION = 3600.0
88
+
81
89
 
82
90
  def supported_formats(ffmpeg: Optional[str] = None) -> Dict[str, str]:
83
91
  """Which extensions this machine can write, and what writes them."""
@@ -420,13 +428,18 @@ class Recorder:
420
428
 
421
429
  # -- internals -------------------------------------------------------------------
422
430
  def _run(self) -> None:
423
- deadline = None if self.duration is None else self._started + self.duration
431
+ # A hard ceiling as well as the caller's own limit. The thread keeps a reference to this
432
+ # recorder while it runs, so a recorder that is dropped without ``stop()`` cannot be
433
+ # collected and would otherwise capture forever — and its ffmpeg child with it. With the
434
+ # ceiling, an abandoned recorder finalises itself and exits.
435
+ requested = self.duration if self.duration is not None else MAX_DURATION
436
+ deadline = self._started + min(requested, MAX_DURATION)
424
437
  next_at = self._started
425
438
  try:
426
439
  while not self._stop.is_set():
427
440
  now = time.monotonic()
428
- if deadline is not None and now >= deadline:
429
- self._stopped_by = "duration"
441
+ if now >= deadline:
442
+ self._stopped_by = "duration" if self.duration is not None else "max_duration"
430
443
  break
431
444
  if self.max_frames is not None and self._frames >= self.max_frames:
432
445
  self._stopped_by = "max_frames"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: VirtualDesktop
3
- Version: 1.6.1
3
+ Version: 1.6.2
4
4
  Summary: win10-win11 虚拟桌面
5
5
  Author: VirtualDesktop contributors
6
6
  License: MIT License
@@ -575,6 +575,7 @@ with space.record_stream("run.gif", target=window, fps=8, duration=5) as stream:
575
575
  | `fps` | 目标帧率(必填,默认 10)。低于目标会被丢弃并计入 `report().dropped` |
576
576
  | `duration` | 秒;到点自动停止,`stopped_by="duration"` |
577
577
  | `max_frames` | 帧数上限;到点自动停止,`stopped_by="max_frames"` |
578
+ | — | 不传 `duration` 时有一个 **1 小时硬上限**(`MAX_DURATION`):录制线程持有 `Recorder` 引用,被丢弃且未 `stop()` 的对象无法回收,没有上限就会一直录下去(并带着 ffmpeg 子进程)。正常用法请始终用 `with` |
578
579
  | `quality` | 见上方格式表;不同后端含义不同 |
579
580
  | `format` | 覆盖扩展名推断 |
580
581
  | `on_frame` | `(frame, index)` 回调,每帧一次;回调抛异常不会中断录制 |
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "VirtualDesktop"
7
- version = "1.6.1"
7
+ version = "1.6.2"
8
8
  description = "win10-win11 虚拟桌面"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -255,6 +255,60 @@ def test_record_stream_yields_frames_and_terminates(tmp_path):
255
255
  assert all(w > 0 and h > 0 for w, h in seen)
256
256
 
257
257
 
258
+ def test_max_duration_is_the_ceiling_when_no_duration_is_given():
259
+ """An abandoned recorder must not capture forever.
260
+
261
+ The capture thread keeps a reference to its ``Recorder``, so one dropped without ``stop()`` is
262
+ never collected and would run indefinitely — with its ffmpeg child. ``MAX_DURATION`` bounds it.
263
+ The bound is applied rather than slept through: this checks the deadline arithmetic, because
264
+ waiting an hour is not a test.
265
+ """
266
+ from VirtualDesktop.record import MAX_DURATION
267
+
268
+ with _shared() as space:
269
+ entry = space.launch([CHARMAP], timeout=45.0)
270
+ recorder = space.record_window(entry.hwnd, "unused.gif", fps=1)
271
+ assert recorder.duration is None
272
+ recorder._started = 12345.0
273
+ requested = recorder.duration if recorder.duration is not None else MAX_DURATION
274
+ effective = min(requested, MAX_DURATION)
275
+ assert effective == MAX_DURATION
276
+ # An explicit longer duration is still capped, so the ceiling is real rather than decorative.
277
+ recorder.duration = MAX_DURATION * 10
278
+ assert min(recorder.duration, MAX_DURATION) == MAX_DURATION
279
+ # A shorter explicit duration wins, which is the normal case.
280
+ recorder.duration = 5.0
281
+ assert min(recorder.duration, MAX_DURATION) == 5.0
282
+
283
+
284
+ def test_repeated_recordings_do_not_leak_ffmpeg_processes(tmp_path):
285
+ """Each finished recording must reap its encoder process."""
286
+ import subprocess as sp
287
+
288
+ if not shutil.which("ffmpeg"):
289
+ pytest.skip("ffmpeg is not on PATH")
290
+
291
+ def ffmpeg_count() -> int:
292
+ out = sp.run(
293
+ ["tasklist", "/FI", "IMAGENAME eq ffmpeg.exe", "/FO", "CSV", "/NH"],
294
+ capture_output=True, text=True,
295
+ ).stdout
296
+ return sum(1 for line in out.splitlines() if "ffmpeg" in line.lower())
297
+
298
+ before = ffmpeg_count()
299
+ with _shared() as space:
300
+ entry = space.launch([CHARMAP], timeout=45.0)
301
+ for index in range(3):
302
+ with space.record_window(
303
+ entry.hwnd, tmp_path / f"clip{index}.mp4", fps=8, duration=0.4
304
+ ) as rec:
305
+ time.sleep(0.6)
306
+ assert rec.report().ok
307
+ after = ffmpeg_count()
308
+
309
+ assert after <= before, f"ffmpeg processes leaked: {before} -> {after}"
310
+
311
+
258
312
  def test_on_frame_callback_sees_every_frame(tmp_path):
259
313
  seen = []
260
314
  with _shared() as space:
File without changes
File without changes