@danhachuel/thunderbolt 0.7.12 → 0.7.13

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.
@@ -448,7 +448,7 @@ def ensure_storage() -> None:
448
448
 
449
449
  _LOCK_TIMEOUT_SECONDS = 30.0
450
450
  _LOCK_POLL_SECONDS = 0.05
451
- _LOCK_STALE_SECONDS = 15 * 60
451
+ _LOCK_STALE_SECONDS = 120
452
452
  _PROTECTED_STATE_FILES = {"channels.json", "tasks.json", "batches.json", "queues.json", "uploads.json"}
453
453
 
454
454
 
@@ -466,6 +466,12 @@ def _state_lock(path: Path, *, read_only: bool = False) -> Iterator[None]:
466
466
  """
467
467
  lock_path = path.with_name(f".{path.name}.lock")
468
468
  lock_path.parent.mkdir(parents=True, exist_ok=True)
469
+ if read_only:
470
+ # JSON writes use os.replace(), so a reader can safely read either the
471
+ # old complete file or the new complete file. Never make page loads
472
+ # wait for a writer/antivirus handle on Windows.
473
+ yield
474
+ return
469
475
  deadline = time.monotonic() + _LOCK_TIMEOUT_SECONDS
470
476
  descriptor: int | None = None
471
477
  while descriptor is None:
@@ -483,7 +489,22 @@ def _state_lock(path: Path, *, read_only: bool = False) -> Iterator[None]:
483
489
  return
484
490
  except FileExistsError:
485
491
  try:
486
- if time.time() - lock_path.stat().st_mtime > _LOCK_STALE_SECONDS:
492
+ lock_age = time.time() - lock_path.stat().st_mtime
493
+ owner_pid = ""
494
+ try:
495
+ owner_pid = lock_path.read_text(encoding="ascii").split("pid=", 1)[1].splitlines()[0].strip()
496
+ except (IndexError, OSError, UnicodeDecodeError):
497
+ pass
498
+ owner_alive = False
499
+ if owner_pid.isdigit():
500
+ try:
501
+ os.kill(int(owner_pid), 0)
502
+ owner_alive = True
503
+ except PermissionError:
504
+ owner_alive = True
505
+ except (ProcessLookupError, OSError):
506
+ owner_alive = False
507
+ if (owner_pid and not owner_alive) or (not owner_pid and lock_age > _LOCK_STALE_SECONDS):
487
508
  lock_path.unlink()
488
509
  continue
489
510
  except OSError:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danhachuel/thunderbolt",
3
- "version": "0.7.12",
3
+ "version": "0.7.13",
4
4
  "description": "Thunderbolt — interface local para operação de canais faceless e motor MoneyPrinterTurbo",
5
5
  "license": "MIT",
6
6
  "main": "scripts/cli.mjs",