quapp-common 0.0.17.dev1__tar.gz → 0.0.17.dev3__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 (118) hide show
  1. {quapp_common-0.0.17.dev1/quapp_common.egg-info → quapp_common-0.0.17.dev3}/PKG-INFO +29 -1
  2. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/README.md +28 -0
  3. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/pyproject.toml +1 -1
  4. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/config/logging_config.py +18 -10
  5. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3/quapp_common.egg-info}/PKG-INFO +29 -1
  6. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/tests/test_job_log_capture.py +50 -1
  7. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/LICENSE +0 -0
  8. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/__init__.py +0 -0
  9. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/async_tasks/__init__.py +0 -0
  10. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/async_tasks/async_invocation_task.py +0 -0
  11. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/async_tasks/async_task.py +0 -0
  12. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/async_tasks/export_circuit_task.py +0 -0
  13. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/async_tasks/post_processing_task.py +0 -0
  14. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/component/__init__.py +0 -0
  15. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/component/backend/__init__.py +0 -0
  16. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/component/backend/invocation.py +0 -0
  17. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/component/backend/job_fetcher.py +0 -0
  18. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/component/backend/job_fetching.py +0 -0
  19. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/component/backend/job_heartbeat.py +0 -0
  20. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/component/backend/job_manager.py +0 -0
  21. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/component/bridge.py +0 -0
  22. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/component/callback/__init__.py +0 -0
  23. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/component/callback/update_job_metadata.py +0 -0
  24. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/component/circuit_adapter.py +0 -0
  25. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/component/device/__init__.py +0 -0
  26. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/component/device/device_selection.py +0 -0
  27. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/component/dispatcher.py +0 -0
  28. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/component/result_serializer.py +0 -0
  29. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/config/__init__.py +0 -0
  30. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/config/log_context.py +0 -0
  31. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/config/thread_config.py +0 -0
  32. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/__init__.py +0 -0
  33. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/async_task/__init__.py +0 -0
  34. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/async_task/circuit_export/__init__.py +0 -0
  35. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/async_task/circuit_export/backend_holder.py +0 -0
  36. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/async_task/circuit_export/circuit_holder.py +0 -0
  37. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/backend/__init__.py +0 -0
  38. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/backend/backend_information.py +0 -0
  39. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/callback/__init__.py +0 -0
  40. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/callback/callback_url.py +0 -0
  41. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/device/__init__.py +0 -0
  42. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/device/circuit_running_option.py +0 -0
  43. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/promise/__init__.py +0 -0
  44. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/promise/post_processing_promise.py +0 -0
  45. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/promise/promise.py +0 -0
  46. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/request/__init__.py +0 -0
  47. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/request/invocation_request.py +0 -0
  48. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/request/job_fetching_request.py +0 -0
  49. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/request/request.py +0 -0
  50. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/response/__init__.py +0 -0
  51. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/response/authentication.py +0 -0
  52. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/response/custom_header.py +0 -0
  53. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/response/error_report.py +0 -0
  54. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/data/response/job_response.py +0 -0
  55. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/enum/__init__.py +0 -0
  56. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/enum/base_enum.py +0 -0
  57. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/enum/error_category.py +0 -0
  58. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/enum/http_header.py +0 -0
  59. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/enum/invocation_step.py +0 -0
  60. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/enum/language.py +0 -0
  61. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/enum/media_type.py +0 -0
  62. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/enum/processing_unit.py +0 -0
  63. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/enum/provider_tag.py +0 -0
  64. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/enum/runtime_phase.py +0 -0
  65. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/enum/sdk.py +0 -0
  66. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/enum/status/__init__.py +0 -0
  67. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/enum/status/job_status.py +0 -0
  68. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/enum/status/status_code.py +0 -0
  69. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/enum/token_type.py +0 -0
  70. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/factory/__init__.py +0 -0
  71. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/factory/device_factory.py +0 -0
  72. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/factory/handler_factory.py +0 -0
  73. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/factory/provider_factory.py +0 -0
  74. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/handler/__init__.py +0 -0
  75. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/handler/handler.py +0 -0
  76. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/joblog/__init__.py +0 -0
  77. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/joblog/capture.py +0 -0
  78. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/joblog/child.py +0 -0
  79. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/joblog/ingest.py +0 -0
  80. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/joblog/pipes.py +0 -0
  81. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/joblog/shipper.py +0 -0
  82. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/model/__init__.py +0 -0
  83. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/model/device/__init__.py +0 -0
  84. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/model/device/custom_device.py +0 -0
  85. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/model/device/device.py +0 -0
  86. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/model/invocation.py +0 -0
  87. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/model/provider/__init__.py +0 -0
  88. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/model/provider/provider.py +0 -0
  89. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/util/__init__.py +0 -0
  90. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/util/error_classifier.py +0 -0
  91. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/util/file_utils.py +0 -0
  92. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/util/http_utils.py +0 -0
  93. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/util/invocation_failure.py +0 -0
  94. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/util/json_parser_utils.py +0 -0
  95. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/util/process_utils.py +0 -0
  96. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common/util/response_utils.py +0 -0
  97. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common.egg-info/SOURCES.txt +0 -0
  98. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common.egg-info/dependency_links.txt +0 -0
  99. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common.egg-info/requires.txt +0 -0
  100. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/quapp_common.egg-info/top_level.txt +0 -0
  101. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/setup.cfg +0 -0
  102. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/tests/test_callback_payload.py +0 -0
  103. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/tests/test_circuit_adapter.py +0 -0
  104. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/tests/test_compute_process.py +0 -0
  105. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/tests/test_dispatcher_runner_error.py +0 -0
  106. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/tests/test_error_classifier.py +0 -0
  107. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/tests/test_error_log_dedupe.py +0 -0
  108. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/tests/test_error_report.py +0 -0
  109. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/tests/test_fork_socket_inheritance.py +0 -0
  110. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/tests/test_invocation_failure.py +0 -0
  111. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/tests/test_job_heartbeat.py +0 -0
  112. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/tests/test_json_parser_utils.py +0 -0
  113. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/tests/test_language_dispatcher.py +0 -0
  114. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/tests/test_log_secret_leak.py +0 -0
  115. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/tests/test_logging_config.py +0 -0
  116. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/tests/test_no_sdk_dependency.py +0 -0
  117. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/tests/test_phase_coverage.py +0 -0
  118. {quapp_common-0.0.17.dev1 → quapp_common-0.0.17.dev3}/tests/test_result_serializer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quapp-common
3
- Version: 0.0.17.dev1
3
+ Version: 0.0.17.dev3
4
4
  Summary: Quapp common library supporting Quapp Platform for Quantum Computing
5
5
  Author-email: "CITYNOW Co. Ltd. " <corp@citynow.vn>
6
6
  License: The MIT License (MIT)
@@ -111,6 +111,34 @@ Notes:
111
111
 
112
112
  ## Recently Changes Highlights
113
113
 
114
+ ### v0.0.17.dev3 — Thư viện không đổi, chạy thử release wrapper tự động
115
+
116
+ Code giống hệt `0.0.17.dev2`. Bản này để chạy vòng đầu của job CI `release_wrappers`:
117
+ tag `.devN` publish xong thì pipeline kích hoạt quapp-migration. Bot ở đó nâng pin
118
+ quapp-common của từng wrapper, release từng wrapper rồi mở MR catalog dev (xem
119
+ `sdk-catalog/README.md` của quapp-migration, mục "Phát hành wrapper theo
120
+ quapp-common").
121
+
122
+ ### v0.0.17.dev2 — Sửa server treo khi fork lúc đang ghi log
123
+
124
+ Sink loguru của process server (`configure_logging`) đổi từ `enqueue=True` sang
125
+ `enqueue=False`.
126
+
127
+ - **Lỗi:** với `enqueue=True`, hook at-fork của loguru khoá các lock của handler
128
+ theo thứ tự tuỳ ý (`WeakSet`). Khi nó cầm lock hàng đợi rồi chờ lock của handler,
129
+ trong khi một luồng khác đang giữ lock đó và chờ hàng đợi có chỗ (pipe hàng đợi
130
+ đầy), còn luồng xả hàng đợi lại chờ lock hàng đợi, thì fork không bao giờ trả về:
131
+ server treo ngay lúc tạo compute process, heartbeat hoặc `SyncManager`. Có từ
132
+ `0.0.15` (fork mỗi job); loguru 0.7.3 vẫn còn lỗi này.
133
+ - **Sửa:** ghi thẳng ra stderr, không còn luồng xả hàng đợi nên không còn vòng chờ.
134
+ Traceback vẫn được format sẵn trong filter. Đổi lại, dòng log dài hơn 4 KB
135
+ (`PIPE_BUF`) từ nhiều process ghi cùng lúc có thể xen nhau trong log container;
136
+ log job (PQF-23860) đi qua pipe riêng từng job nên không bị.
137
+ - **Test:** `test_server_sinks_write_without_a_queue` và
138
+ `test_forking_many_times_while_the_parent_logs_never_hangs` (30 lần fork trong
139
+ luồng phụ, treo thì fail thay vì treo cả bộ test). Trên code cũ: treo 9/40 lần ở
140
+ test fork 10 lần; stress test bắt được ở 2/3 lần chạy.
141
+
114
142
  ### v0.0.17.dev1 — Log job trực tiếp về backend (PQF-23860)
115
143
 
116
144
  Runtime đẩy log của từng job về backend trong lúc job chạy. Loki vẫn là đường dự
@@ -73,6 +73,34 @@ Notes:
73
73
 
74
74
  ## Recently Changes Highlights
75
75
 
76
+ ### v0.0.17.dev3 — Thư viện không đổi, chạy thử release wrapper tự động
77
+
78
+ Code giống hệt `0.0.17.dev2`. Bản này để chạy vòng đầu của job CI `release_wrappers`:
79
+ tag `.devN` publish xong thì pipeline kích hoạt quapp-migration. Bot ở đó nâng pin
80
+ quapp-common của từng wrapper, release từng wrapper rồi mở MR catalog dev (xem
81
+ `sdk-catalog/README.md` của quapp-migration, mục "Phát hành wrapper theo
82
+ quapp-common").
83
+
84
+ ### v0.0.17.dev2 — Sửa server treo khi fork lúc đang ghi log
85
+
86
+ Sink loguru của process server (`configure_logging`) đổi từ `enqueue=True` sang
87
+ `enqueue=False`.
88
+
89
+ - **Lỗi:** với `enqueue=True`, hook at-fork của loguru khoá các lock của handler
90
+ theo thứ tự tuỳ ý (`WeakSet`). Khi nó cầm lock hàng đợi rồi chờ lock của handler,
91
+ trong khi một luồng khác đang giữ lock đó và chờ hàng đợi có chỗ (pipe hàng đợi
92
+ đầy), còn luồng xả hàng đợi lại chờ lock hàng đợi, thì fork không bao giờ trả về:
93
+ server treo ngay lúc tạo compute process, heartbeat hoặc `SyncManager`. Có từ
94
+ `0.0.15` (fork mỗi job); loguru 0.7.3 vẫn còn lỗi này.
95
+ - **Sửa:** ghi thẳng ra stderr, không còn luồng xả hàng đợi nên không còn vòng chờ.
96
+ Traceback vẫn được format sẵn trong filter. Đổi lại, dòng log dài hơn 4 KB
97
+ (`PIPE_BUF`) từ nhiều process ghi cùng lúc có thể xen nhau trong log container;
98
+ log job (PQF-23860) đi qua pipe riêng từng job nên không bị.
99
+ - **Test:** `test_server_sinks_write_without_a_queue` và
100
+ `test_forking_many_times_while_the_parent_logs_never_hangs` (30 lần fork trong
101
+ luồng phụ, treo thì fail thay vì treo cả bộ test). Trên code cũ: treo 9/40 lần ở
102
+ test fork 10 lần; stress test bắt được ở 2/3 lần chạy.
103
+
76
104
  ### v0.0.17.dev1 — Log job trực tiếp về backend (PQF-23860)
77
105
 
78
106
  Runtime đẩy log của từng job về backend trong lúc job chạy. Loki vẫn là đường dự
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "quapp-common"
7
- version = "0.0.17.dev1"
7
+ version = "0.0.17.dev3"
8
8
  description = "Quapp common library supporting Quapp Platform for Quantum Computing"
9
9
  readme = "README.md"
10
10
  authors = [{ name = "CITYNOW Co. Ltd. ", email = "corp@citynow.vn" }]
@@ -135,11 +135,11 @@ def _inject_job_context(record) -> None:
135
135
  def _prepare_record(record) -> bool:
136
136
  """loguru filter: fill in context, mask the message, pre-format the traceback.
137
137
 
138
- The filter runs in the process that logged, BEFORE the record is put on the
139
- ``enqueue=True`` queue. This is the only place that can still see the real
140
- traceback object -- once through the queue, the traceback is not picklable so
141
- it is replaced with None and ``traceback.format_exception()`` inside the sink
142
- can only produce the last line.
138
+ The filter runs in the process that logged, before any sink. The traceback is
139
+ formatted here, so a sink never depends on the traceback object itself: it
140
+ would not survive a pickling queue (``enqueue=True``, which the sinks no
141
+ longer use, see ``configure_logging``), where it is replaced with None and
142
+ ``traceback.format_exception()`` can only produce the last line.
143
143
 
144
144
  Returns True to keep the record.
145
145
  """
@@ -296,6 +296,14 @@ def configure_logging(force: bool = False) -> None:
296
296
 
297
297
  logger.remove()
298
298
 
299
+ # enqueue=False is MANDATORY: this process forks (a compute process per job,
300
+ # the heartbeat, the SyncManager). With enqueue=True, loguru's at-fork hook
301
+ # takes the handler locks in WeakSet order; when it holds the queue lock and
302
+ # waits for the handler lock while another thread holds that lock, blocked on
303
+ # a full queue that only the writer thread -- itself waiting for the queue
304
+ # lock -- can drain, the fork never returns and the server hangs. Writing
305
+ # directly leaves no writer thread, so no cycle (~1 hang in 4 runs of
306
+ # test_forking_while_the_parent_logs_never_hangs before, none after).
299
307
  if LOG_FORMAT in ('text', 'both'):
300
308
  # diagnose=False is MANDATORY: loguru's diagnose prints local variable
301
309
  # values inside the traceback as `└ 'value'`. There is no key name, so
@@ -304,12 +312,12 @@ def configure_logging(force: bool = False) -> None:
304
312
  # verbatim. backtrace=True stays: it widens the call chain but prints no
305
313
  # values.
306
314
  logger.add(sink=sys.stderr, format=__custom_format, level=LOG_LEVEL,
307
- colorize=True, filter=_prepare_record, enqueue=True,
315
+ colorize=True, filter=_prepare_record, enqueue=False,
308
316
  backtrace=True, diagnose=False)
309
317
 
310
318
  if LOG_FORMAT in ('json', 'both'):
311
319
  logger.add(sink=_json_sink, level=LOG_LEVEL, filter=_prepare_record,
312
- enqueue=True, backtrace=False, diagnose=False)
320
+ enqueue=False, backtrace=False, diagnose=False)
313
321
 
314
322
  install_stdlib_intercept()
315
323
 
@@ -319,9 +327,9 @@ def configure_logging(force: bool = False) -> None:
319
327
  def configure_child_logging() -> None:
320
328
  """Re-create the sinks in a captured compute process (PQF-23860).
321
329
 
322
- The inherited sinks write through the parent's ``sys.stderr`` object and
323
- ``enqueue=True`` queue; the child replaced ``sys.stderr`` with a fresh object
324
- on its log pipe, so the sinks are rebuilt on that one. ``remove()`` is safe
330
+ The inherited sinks write through the parent's ``sys.stderr`` object; the
331
+ child replaced ``sys.stderr`` with a fresh object on its log pipe, so the
332
+ sinks are rebuilt on that one. ``remove()`` is safe
325
333
  after fork: loguru only stops handlers its own process started.
326
334
 
327
335
  ``colorize=False``: the parent recognises this job's lines by their
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quapp-common
3
- Version: 0.0.17.dev1
3
+ Version: 0.0.17.dev3
4
4
  Summary: Quapp common library supporting Quapp Platform for Quantum Computing
5
5
  Author-email: "CITYNOW Co. Ltd. " <corp@citynow.vn>
6
6
  License: The MIT License (MIT)
@@ -111,6 +111,34 @@ Notes:
111
111
 
112
112
  ## Recently Changes Highlights
113
113
 
114
+ ### v0.0.17.dev3 — Thư viện không đổi, chạy thử release wrapper tự động
115
+
116
+ Code giống hệt `0.0.17.dev2`. Bản này để chạy vòng đầu của job CI `release_wrappers`:
117
+ tag `.devN` publish xong thì pipeline kích hoạt quapp-migration. Bot ở đó nâng pin
118
+ quapp-common của từng wrapper, release từng wrapper rồi mở MR catalog dev (xem
119
+ `sdk-catalog/README.md` của quapp-migration, mục "Phát hành wrapper theo
120
+ quapp-common").
121
+
122
+ ### v0.0.17.dev2 — Sửa server treo khi fork lúc đang ghi log
123
+
124
+ Sink loguru của process server (`configure_logging`) đổi từ `enqueue=True` sang
125
+ `enqueue=False`.
126
+
127
+ - **Lỗi:** với `enqueue=True`, hook at-fork của loguru khoá các lock của handler
128
+ theo thứ tự tuỳ ý (`WeakSet`). Khi nó cầm lock hàng đợi rồi chờ lock của handler,
129
+ trong khi một luồng khác đang giữ lock đó và chờ hàng đợi có chỗ (pipe hàng đợi
130
+ đầy), còn luồng xả hàng đợi lại chờ lock hàng đợi, thì fork không bao giờ trả về:
131
+ server treo ngay lúc tạo compute process, heartbeat hoặc `SyncManager`. Có từ
132
+ `0.0.15` (fork mỗi job); loguru 0.7.3 vẫn còn lỗi này.
133
+ - **Sửa:** ghi thẳng ra stderr, không còn luồng xả hàng đợi nên không còn vòng chờ.
134
+ Traceback vẫn được format sẵn trong filter. Đổi lại, dòng log dài hơn 4 KB
135
+ (`PIPE_BUF`) từ nhiều process ghi cùng lúc có thể xen nhau trong log container;
136
+ log job (PQF-23860) đi qua pipe riêng từng job nên không bị.
137
+ - **Test:** `test_server_sinks_write_without_a_queue` và
138
+ `test_forking_many_times_while_the_parent_logs_never_hangs` (30 lần fork trong
139
+ luồng phụ, treo thì fail thay vì treo cả bộ test). Trên code cũ: treo 9/40 lần ở
140
+ test fork 10 lần; stress test bắt được ở 2/3 lần chạy.
141
+
114
142
  ### v0.0.17.dev1 — Log job trực tiếp về backend (PQF-23860)
115
143
 
116
144
  Runtime đẩy log của từng job về backend trong lúc job chạy. Loki vẫn là đường dự
@@ -19,7 +19,7 @@ import pytest
19
19
  from quapp_common.async_tasks.async_invocation_task import \
20
20
  AsyncInvocationTask, fork_context, run_compute
21
21
  from quapp_common.component.callback import update_job_metadata as callback
22
- from quapp_common.config.logging_config import logger
22
+ from quapp_common.config.logging_config import configure_logging, logger
23
23
  from quapp_common.factory.handler_factory import HandlerFactory
24
24
  from quapp_common.joblog import child, pipes
25
25
  from quapp_common.joblog.capture import JobLogCapture
@@ -617,6 +617,55 @@ def test_forking_while_the_parent_logs_never_hangs(ingest_server):
617
617
  talker.join(5)
618
618
 
619
619
 
620
+ def test_server_sinks_write_without_a_queue():
621
+ # An enqueue=True sink starts a "loguru-writer-<id>" thread. Its queue lock
622
+ # is what loguru's at-fork hook can take in the wrong order and deadlock.
623
+ configure_logging(force=True)
624
+
625
+ writers = [thread.name for thread in threading.enumerate()
626
+ if thread.name.startswith('loguru-writer')]
627
+ assert writers == []
628
+
629
+
630
+ def test_forking_many_times_while_the_parent_logs_never_hangs(ingest_server):
631
+ # Same race as above, many more forks. The forks run in a worker thread so a
632
+ # deadlock fails this test instead of hanging the whole run.
633
+ stop = threading.Event()
634
+ forks_done = []
635
+
636
+ def chatter():
637
+ while not stop.is_set():
638
+ logger.debug('parent chatter')
639
+ print('parent print', flush=True)
640
+
641
+ def fork_many():
642
+ for _ in range(30):
643
+ capture = JobLogCapture.prepare(JOB_ID, ingest_server.payload())
644
+ process = fork_context().Process(
645
+ target=run_compute,
646
+ args=(os.getpid(), lambda: print('child ok'),
647
+ capture.child_setup))
648
+ process.start()
649
+ capture.started()
650
+ process.join(WAIT_SEC)
651
+ capture.process_exited(process.exitcode)
652
+ forks_done.append(process.exitcode)
653
+
654
+ talker = threading.Thread(target=chatter, daemon=True)
655
+ forker = threading.Thread(target=fork_many, daemon=True)
656
+ talker.start()
657
+ forker.start()
658
+ try:
659
+ forker.join(120)
660
+ finally:
661
+ stop.set()
662
+ talker.join(5)
663
+
664
+ assert not forker.is_alive(), (
665
+ f'fork hung after {len(forks_done)} of 30 forks while the parent logged')
666
+ assert forks_done == [0] * 30
667
+
668
+
620
669
  def test_other_jobs_pipes_are_not_held_by_a_child(ingest_server):
621
670
  first = JobLogCapture.prepare(JOB_ID, ingest_server.payload())
622
671
  second = JobLogCapture.prepare(JOB_ID, ingest_server.payload())