sensor-sdk 0.1.4__tar.gz → 0.1.5__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 (28) hide show
  1. {sensor_sdk-0.1.4/sensor_sdk.egg-info → sensor_sdk-0.1.5}/PKG-INFO +1 -1
  2. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor/sensor_data_context.py +8 -2
  3. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor/sensor_utils.py +24 -23
  4. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5/sensor_sdk.egg-info}/PKG-INFO +1 -1
  5. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/setup.py +1 -1
  6. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/LICENSE.txt +0 -0
  7. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/README.md +0 -0
  8. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor/__init__.py +0 -0
  9. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor/bleak_host.py +0 -0
  10. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor/bleak_process.py +0 -0
  11. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor/fb/DataType.py +0 -0
  12. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor/fb/Sample.py +0 -0
  13. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor/fb/SensorData.py +0 -0
  14. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor/fb/__init__.py +0 -0
  15. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor/gforce.py +0 -0
  16. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor/sdk_log.py +0 -0
  17. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor/sensor_controller.py +0 -0
  18. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor/sensor_data.py +0 -0
  19. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor/sensor_data_pool.py +0 -0
  20. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor/sensor_device.py +0 -0
  21. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor/sensor_profile.py +0 -0
  22. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor/winrt_high_throughput.py +0 -0
  23. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor_sdk.egg-info/SOURCES.txt +0 -0
  24. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor_sdk.egg-info/dependency_links.txt +0 -0
  25. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor_sdk.egg-info/requires.txt +0 -0
  26. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor_sdk.egg-info/top_level.txt +0 -0
  27. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/sensor_sdk.egg-info/zip-safe +0 -0
  28. {sensor_sdk-0.1.4 → sensor_sdk-0.1.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sensor-sdk
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: Python sdk for Synchroni
5
5
  Home-page: https://github.com/oymotion/SynchroniSDKPython
6
6
  Author: Martin Ye
@@ -1476,9 +1476,15 @@ class SensorProfileDataCtx:
1476
1476
  lostSampleCount: int,
1477
1477
  ):
1478
1478
  sampleCount = sensorData.packageSampleCount
1479
+ def _type_name():
1480
+ try:
1481
+ return DataType(sensorData.dataType).name
1482
+ except Exception:
1483
+ return str(sensorData.dataType)
1484
+
1479
1485
  if lostSampleCount <= 0:
1480
1486
  if data is None or offset < 0 or offset > len(data):
1481
- raise ValueError("Invalid data or offset")
1487
+ raise ValueError(f"Invalid data or offset for data type {_type_name()}")
1482
1488
 
1483
1489
  if sensorData.resolutionBits in (7, 8):
1484
1490
  bytesPerChannel = 1
@@ -1499,7 +1505,7 @@ class SensorProfileDataCtx:
1499
1505
  realChannelCount += 1
1500
1506
 
1501
1507
  if offset + ((bytesPerChannel * realChannelCount * sampleCount) + (dataGap * (sampleCount - 1))) > dataLength:
1502
- raise ValueError(f"Invalid dataLength:{dataLength}")
1508
+ raise ValueError(f"Invalid dataLength:{dataLength} for data type {_type_name()}")
1503
1509
 
1504
1510
 
1505
1511
  sampleInterval = (
@@ -38,33 +38,34 @@ def Terminate():
38
38
  global _runloop, _needCloseRunloop, _event_thread, _terminated
39
39
  _terminated = True
40
40
 
41
+ # 如果不是我们创建的 loop(例如用户自己的 qasync/Qt loop),不要动它
42
+ if not _needCloseRunloop or _runloop is None:
43
+ return
44
+
41
45
  def _cancel_tasks():
42
- for task in asyncio.all_tasks():
43
- task.cancel()
46
+ try:
47
+ # 在 loop 线程内部调用,有运行中的事件循环
48
+ for task in asyncio.all_tasks():
49
+ if not task.done():
50
+ task.cancel()
51
+ except Exception:
52
+ # 取消任务失败时不阻塞终止流程
53
+ pass
44
54
 
45
55
  try:
46
- _cancel_tasks()
47
- except RuntimeError:
48
- # 当前线程没有运行的事件循环,尝试在管理的 runloop 上取消任务
49
- if _runloop is not None and _runloop.is_running():
50
- try:
51
- _runloop.call_soon_threadsafe(_cancel_tasks)
52
- time.sleep(0.1)
53
- except Exception as e:
54
- SdkLog.exception(_TAG, "Error cancelling tasks during terminate")
55
- except Exception as e:
56
- SdkLog.exception(_TAG, "Error cancelling tasks during terminate")
56
+ # 取消 / stop 都必须在 loop 所在线程执行,避免跨线程调用 asyncio API 抛异常
57
+ if _runloop.is_running():
58
+ _runloop.call_soon_threadsafe(_cancel_tasks)
59
+ time.sleep(0.2)
60
+ _runloop.call_soon_threadsafe(_runloop.stop)
57
61
 
58
- if _needCloseRunloop:
59
- try:
60
- if _runloop is not None and _runloop.is_running():
61
- _runloop.call_soon_threadsafe(_runloop.stop)
62
- if _event_thread is not None and _event_thread.is_alive():
63
- _event_thread.join(timeout=2.0)
64
- if _runloop is not None and not _runloop.is_running():
65
- _runloop.close()
66
- except Exception as e:
67
- SdkLog.exception(_TAG, "Error closing runloop during terminate")
62
+ if _event_thread is not None and _event_thread.is_alive():
63
+ _event_thread.join(timeout=3.0)
64
+
65
+ # 不再主动 close loop:Windows 的 ProactorEventLoop 在 still-running 时 close()
66
+ # 会抛 RuntimeError。守护线程会在 loop stop 后自然退出,进程退出时回收资源。
67
+ except Exception as e:
68
+ SdkLog.exception(_TAG, "Error during terminate")
68
69
 
69
70
 
70
71
  def async_exec(function, runloop=None):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sensor-sdk
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: Python sdk for Synchroni
5
5
  Home-page: https://github.com/oymotion/SynchroniSDKPython
6
6
  Author: Martin Ye
@@ -8,7 +8,7 @@ with open(os.path.join(this_directory, "README.md"), "r", encoding="utf-8") as f
8
8
 
9
9
  setup(
10
10
  name="sensor-sdk",
11
- version="0.1.4",
11
+ version="0.1.5",
12
12
  description="Python sdk for Synchroni",
13
13
  long_description=long_description,
14
14
  long_description_content_type="text/markdown",
File without changes
File without changes
File without changes
File without changes
File without changes