pyobs-flipro 2.0.0.dev9__tar.gz → 2.0.0.dev11__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.
- pyobs_flipro-2.0.0.dev11/.github/workflows/dependabot-automerge.yml +24 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/PKG-INFO +1 -1
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/pyobs_flipro/fliprocamera.py +32 -9
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/pyobs_flipro/fliprodriver.pyx +106 -30
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/pyobs_flipro/libflipro.pxd +1 -1
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/pyproject.toml +1 -1
- pyobs_flipro-2.0.0.dev11/specs/plans/2026-08-16-nogil-libflipro-driver-calls.md +104 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/tests/test_fliprocamera.py +9 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/uv.lock +25 -25
- pyobs_flipro-2.0.0.dev9/poetry.lock +0 -2257
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/.github/dependabot.yml +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/.github/workflows/pypi.yml +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/.github/workflows/pyrefly.yml +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/.github/workflows/pytest.yml +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/.github/workflows/ruff.yml +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/.pre-commit-config.yaml +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/.readthedocs.yml +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/CMakeLists.txt +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/LICENSE +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/README.md +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/docs/Makefile +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/docs/make.bat +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/docs/requirements.txt +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/docs/source/_static/pyobs.gif +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/docs/source/conf.py +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/docs/source/index.rst +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/lib/libflipro.h +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/lib/liblibflialgo.so +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/lib/liblibflipro.so +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/pyobs_flipro/__init__.py +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/pyobs_flipro/gui.py +0 -0
- {pyobs_flipro-2.0.0.dev9 → pyobs_flipro-2.0.0.dev11}/tests/test_import.py +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: Dependabot auto-merge
|
|
2
|
+
|
|
3
|
+
on: pull_request
|
|
4
|
+
|
|
5
|
+
permissions:
|
|
6
|
+
contents: write
|
|
7
|
+
pull-requests: write
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
dependabot:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
|
|
13
|
+
steps:
|
|
14
|
+
- name: Fetch Dependabot metadata
|
|
15
|
+
id: metadata
|
|
16
|
+
uses: dependabot/fetch-metadata@v2
|
|
17
|
+
with:
|
|
18
|
+
compat-lookup: true
|
|
19
|
+
- name: Enable auto-merge for patch and minor updates
|
|
20
|
+
if: ${{ steps.metadata.outputs.update-type == 'version-update:semver-patch' || steps.metadata.outputs.update-type == 'version-update:semver-minor' }}
|
|
21
|
+
run: gh pr merge --auto --merge "$PR_URL"
|
|
22
|
+
env:
|
|
23
|
+
PR_URL: ${{ github.event.pull_request.html_url }}
|
|
24
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -66,6 +66,10 @@ class FliProCamera(BaseCamera, ICamera, IAbortable, IWindow, IBinning, ICooling,
|
|
|
66
66
|
# cooling state
|
|
67
67
|
self._cooling_enabled = False
|
|
68
68
|
|
|
69
|
+
# serializes all FLIPRO SDK calls; the SDK's own thread-safety is unverified, and the
|
|
70
|
+
# cooling-poll task and exposure threads share the same handle.
|
|
71
|
+
self._sdk_lock = threading.Lock()
|
|
72
|
+
|
|
69
73
|
# background task for polling cooling/temperature
|
|
70
74
|
self.add_background_task(self._poll_cooling)
|
|
71
75
|
|
|
@@ -78,6 +82,9 @@ class FliProCamera(BaseCamera, ICamera, IAbortable, IWindow, IBinning, ICooling,
|
|
|
78
82
|
|
|
79
83
|
Returns:
|
|
80
84
|
True if func completed within timeout, False if it's still running in the background.
|
|
85
|
+
|
|
86
|
+
Raises:
|
|
87
|
+
The exception raised by func, if any.
|
|
81
88
|
"""
|
|
82
89
|
loop = asyncio.get_running_loop()
|
|
83
90
|
future: asyncio.Future[None] = loop.create_future()
|
|
@@ -85,7 +92,9 @@ class FliProCamera(BaseCamera, ICamera, IAbortable, IWindow, IBinning, ICooling,
|
|
|
85
92
|
def _wrapper() -> None:
|
|
86
93
|
try:
|
|
87
94
|
func()
|
|
88
|
-
|
|
95
|
+
except BaseException as e:
|
|
96
|
+
loop.call_soon_threadsafe(future.set_exception, e)
|
|
97
|
+
else:
|
|
89
98
|
loop.call_soon_threadsafe(future.set_result, None)
|
|
90
99
|
|
|
91
100
|
threading.Thread(target=_wrapper, daemon=True).start()
|
|
@@ -106,10 +115,11 @@ class FliProCamera(BaseCamera, ICamera, IAbortable, IWindow, IBinning, ICooling,
|
|
|
106
115
|
outcome: list[Any] = []
|
|
107
116
|
|
|
108
117
|
def _wrapper() -> None:
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
118
|
+
with self._sdk_lock:
|
|
119
|
+
try:
|
|
120
|
+
outcome.append(func())
|
|
121
|
+
except BaseException as e:
|
|
122
|
+
outcome.append(e)
|
|
113
123
|
|
|
114
124
|
if not await self._run_blocking(_wrapper, timeout=timeout):
|
|
115
125
|
raise TimeoutError(f"Timed out waiting for FLIPRO SDK call after {timeout}s.")
|
|
@@ -140,7 +150,12 @@ class FliProCamera(BaseCamera, ICamera, IAbortable, IWindow, IBinning, ICooling,
|
|
|
140
150
|
raise ValueError(f"Could not open FLIPRO camera: {e}")
|
|
141
151
|
|
|
142
152
|
# get caps
|
|
143
|
-
|
|
153
|
+
try:
|
|
154
|
+
self._caps = self._driver.get_capabilities()
|
|
155
|
+
except Exception:
|
|
156
|
+
self._driver.close()
|
|
157
|
+
self._driver = None
|
|
158
|
+
raise
|
|
144
159
|
self._log_capabilities()
|
|
145
160
|
|
|
146
161
|
# store full frame from caps
|
|
@@ -193,8 +208,16 @@ class FliProCamera(BaseCamera, ICamera, IAbortable, IWindow, IBinning, ICooling,
|
|
|
193
208
|
if self._driver is not None:
|
|
194
209
|
driver = self._driver
|
|
195
210
|
self._driver = None
|
|
196
|
-
|
|
197
|
-
|
|
211
|
+
|
|
212
|
+
def _close() -> None:
|
|
213
|
+
with self._sdk_lock:
|
|
214
|
+
driver.close()
|
|
215
|
+
|
|
216
|
+
try:
|
|
217
|
+
if not await self._run_blocking(_close):
|
|
218
|
+
log.error("Timed out closing FLIPRO camera after %.1fs.", _SDK_CALL_TIMEOUT)
|
|
219
|
+
except Exception:
|
|
220
|
+
log.exception("Failed to close FLIPRO camera.")
|
|
198
221
|
|
|
199
222
|
def _log_device_info(self) -> None:
|
|
200
223
|
log.info("Device info:")
|
|
@@ -358,7 +381,7 @@ class FliProCamera(BaseCamera, ICamera, IAbortable, IWindow, IBinning, ICooling,
|
|
|
358
381
|
"""Abort the running exposure."""
|
|
359
382
|
if self._driver is None:
|
|
360
383
|
raise ValueError("No camera driver.")
|
|
361
|
-
await self._run_blocking_or_raise(self._driver.
|
|
384
|
+
await self._run_blocking_or_raise(self._driver.stop_exposure)
|
|
362
385
|
|
|
363
386
|
async def set_window(self, left: int, top: int, width: int, height: int, **kwargs: Any) -> None:
|
|
364
387
|
"""Set the camera window.
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
from collections import namedtuple
|
|
4
4
|
from enum import Enum
|
|
5
5
|
from typing import Tuple, List, Optional
|
|
6
|
+
from cpython.unicode cimport PyUnicode_FromWideChar
|
|
6
7
|
from libc.stdlib cimport malloc, free
|
|
7
|
-
from libc.string cimport memcpy
|
|
8
|
+
from libc.string cimport memcpy, memset
|
|
8
9
|
|
|
9
10
|
import numpy as np
|
|
10
11
|
cimport numpy as np
|
|
@@ -19,22 +20,22 @@ cdef class DeviceInfo:
|
|
|
19
20
|
def __init__(self, obj):
|
|
20
21
|
self.obj = obj
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return
|
|
23
|
+
cdef str _decode(self, wchar_t* buf):
|
|
24
|
+
# buf is a NUL-terminated wide string; decode it as such rather than as a narrow C string
|
|
25
|
+
# (which would truncate at the zero padding byte after the first character)
|
|
26
|
+
return PyUnicode_FromWideChar(buf, -1)
|
|
26
27
|
|
|
27
28
|
@property
|
|
28
29
|
def friendly_name(self):
|
|
29
|
-
return self.
|
|
30
|
+
return self._decode(self.obj.cFriendlyName)
|
|
30
31
|
|
|
31
32
|
@property
|
|
32
33
|
def serial_number(self):
|
|
33
|
-
return self.
|
|
34
|
+
return self._decode(self.obj.cSerialNo)
|
|
34
35
|
|
|
35
36
|
@property
|
|
36
37
|
def device_path(self):
|
|
37
|
-
return self.
|
|
38
|
+
return self._decode(self.obj.cDevicePath)
|
|
38
39
|
|
|
39
40
|
@property
|
|
40
41
|
def conn_type(self):
|
|
@@ -94,15 +95,26 @@ cdef class FliProDriver:
|
|
|
94
95
|
cdef wchar_t[100] version
|
|
95
96
|
cdef uint32_t length = 100
|
|
96
97
|
|
|
97
|
-
|
|
98
|
+
memset(version, 0, sizeof(version))
|
|
99
|
+
with nogil:
|
|
100
|
+
success = FPROCam_GetAPIVersion(version, length)
|
|
101
|
+
if success < 0:
|
|
102
|
+
raise ValueError('Could not fetch API version.')
|
|
103
|
+
# version is a wchar_t buffer; treat it as a NUL-terminated wide string rather than a
|
|
104
|
+
# narrow C string, so multi-byte wchar_t code units (4 bytes on Linux) don't truncate
|
|
105
|
+
# the result at the first zero padding byte after the first character
|
|
106
|
+
return PyUnicode_FromWideChar(<wchar_t*>version, -1)
|
|
98
107
|
|
|
99
108
|
@staticmethod
|
|
100
109
|
def list_devices() -> List[DeviceInfo]:
|
|
101
110
|
cdef FPRODEVICEINFO pDeviceInfo[10]
|
|
102
111
|
cdef uint32_t pNumDevices = 10
|
|
112
|
+
cdef LIBFLIPRO_API success
|
|
103
113
|
|
|
104
114
|
# get list of cameras
|
|
105
|
-
|
|
115
|
+
with nogil:
|
|
116
|
+
success = FPROCam_GetCameraList(pDeviceInfo, &pNumDevices)
|
|
117
|
+
if success < 0:
|
|
106
118
|
raise ValueError('Could not fetch list of devices.')
|
|
107
119
|
|
|
108
120
|
# return DeviceInfos
|
|
@@ -119,50 +131,81 @@ cdef class FliProDriver:
|
|
|
119
131
|
return self._device_info
|
|
120
132
|
|
|
121
133
|
def open(self):
|
|
122
|
-
|
|
134
|
+
cdef LIBFLIPRO_API success
|
|
135
|
+
with nogil:
|
|
136
|
+
success = FPROCam_Open(&self._device, &self._handle)
|
|
137
|
+
if success < 0:
|
|
123
138
|
raise ValueError('Could not open camera.')
|
|
124
139
|
|
|
125
140
|
def close(self):
|
|
126
|
-
|
|
141
|
+
cdef LIBFLIPRO_API success
|
|
142
|
+
with nogil:
|
|
143
|
+
success = FPROCam_Close(self._handle)
|
|
144
|
+
if success < 0:
|
|
127
145
|
raise ValueError('Could not close camera.')
|
|
128
146
|
|
|
129
147
|
def get_capabilities(self):
|
|
130
148
|
cdef FPROCAP pCap
|
|
131
149
|
cdef uint32_t pCapLength = sizeof(FPROCAP)
|
|
132
|
-
|
|
150
|
+
cdef LIBFLIPRO_API success
|
|
151
|
+
with nogil:
|
|
152
|
+
success = FPROSensor_GetCapabilities(self._handle, &pCap, &pCapLength)
|
|
153
|
+
if success < 0:
|
|
133
154
|
raise ValueError('Could not fetch camera capabalities.')
|
|
134
155
|
return DeviceCaps(pCap)
|
|
135
156
|
|
|
136
157
|
def get_image_area(self) -> Tuple[int, int, int, int]:
|
|
137
158
|
cdef uint32_t pColOffset, pRowOffset, pWidth, pHeight
|
|
138
|
-
|
|
159
|
+
cdef LIBFLIPRO_API success
|
|
160
|
+
with nogil:
|
|
161
|
+
success = FPROFrame_GetImageArea(self._handle, &pColOffset, &pRowOffset, &pWidth, &pHeight)
|
|
162
|
+
if success < 0:
|
|
139
163
|
raise ValueError('Could not fetch image area.')
|
|
140
164
|
return pColOffset, pRowOffset, pWidth, pHeight
|
|
141
165
|
|
|
142
166
|
def set_image_area(self, col_offset, row_offset, width, height):
|
|
143
|
-
|
|
167
|
+
cdef uint32_t col_c = col_offset
|
|
168
|
+
cdef uint32_t row_c = row_offset
|
|
169
|
+
cdef uint32_t width_c = width
|
|
170
|
+
cdef uint32_t height_c = height
|
|
171
|
+
cdef LIBFLIPRO_API success
|
|
172
|
+
with nogil:
|
|
173
|
+
success = FPROFrame_SetImageArea(self._handle, col_c, row_c, width_c, height_c)
|
|
174
|
+
if success < 0:
|
|
144
175
|
raise ValueError('Could not set image area.')
|
|
145
176
|
|
|
146
177
|
def get_exposure_time(self) -> int:
|
|
147
178
|
cdef uint64_t pExposureTime, pDelay
|
|
148
179
|
cdef bool immediately
|
|
149
|
-
|
|
180
|
+
cdef LIBFLIPRO_API success
|
|
181
|
+
with nogil:
|
|
182
|
+
success = FPROCtrl_GetExposure(self._handle, &pExposureTime, &pDelay, &immediately)
|
|
183
|
+
if success < 0:
|
|
150
184
|
raise ValueError('Could not fetch exposure time.')
|
|
151
185
|
return pExposureTime
|
|
152
186
|
|
|
153
187
|
def set_exposure_time(self, exptime_ns: int):
|
|
154
188
|
cdef LIBFLIPRO_API success
|
|
155
189
|
cdef bool immediately = False
|
|
156
|
-
|
|
190
|
+
cdef uint64_t exptime_c = exptime_ns
|
|
191
|
+
with nogil:
|
|
192
|
+
success = FPROCtrl_SetExposure(self._handle, exptime_c, 0, immediately)
|
|
193
|
+
if success < 0:
|
|
157
194
|
raise ValueError('Could not set exposure time.')
|
|
158
195
|
|
|
159
196
|
def get_frame_size(self):
|
|
160
197
|
# calculate size of the frame to retrieve from camera
|
|
161
|
-
|
|
198
|
+
cdef LIBFLIPRO_API size
|
|
199
|
+
with nogil:
|
|
200
|
+
size = FPROFrame_ComputeFrameSize(self._handle)
|
|
201
|
+
return size
|
|
162
202
|
|
|
163
203
|
def start_exposure(self):
|
|
164
204
|
# start exposure
|
|
165
|
-
|
|
205
|
+
cdef LIBFLIPRO_API success
|
|
206
|
+
with nogil:
|
|
207
|
+
success = FPROFrame_CaptureStart(self._handle, 1)
|
|
208
|
+
if success < 0:
|
|
166
209
|
raise ValueError('Could not start exposure.')
|
|
167
210
|
|
|
168
211
|
def read_exposure(self, frame_size):
|
|
@@ -195,7 +238,10 @@ cdef class FliProDriver:
|
|
|
195
238
|
|
|
196
239
|
# read frame
|
|
197
240
|
# TODO: this fails on images that have not full width of sensor
|
|
198
|
-
|
|
241
|
+
cdef LIBFLIPRO_API success
|
|
242
|
+
with nogil:
|
|
243
|
+
success = FPROFrame_GetVideoFrameUnpacked(self._handle, frame_data, &c_frame_size, 100, &buffers, &stats)
|
|
244
|
+
if success < 0:
|
|
199
245
|
raise ValueError('Could not fetch frame.')
|
|
200
246
|
|
|
201
247
|
# check size
|
|
@@ -211,55 +257,85 @@ cdef class FliProDriver:
|
|
|
211
257
|
|
|
212
258
|
# clean up and return image
|
|
213
259
|
free(frame_data)
|
|
214
|
-
|
|
260
|
+
with nogil:
|
|
261
|
+
FPROFrame_FreeUnpackedBuffers(&buffers)
|
|
215
262
|
return data
|
|
216
263
|
|
|
217
264
|
def stop_exposure(self):
|
|
218
265
|
# start exposure
|
|
219
|
-
|
|
266
|
+
cdef LIBFLIPRO_API success
|
|
267
|
+
with nogil:
|
|
268
|
+
success = FPROFrame_CaptureStop(self._handle)
|
|
269
|
+
if success < 0:
|
|
220
270
|
raise ValueError('Could not stop exposure.')
|
|
221
271
|
|
|
222
272
|
def is_available(self):
|
|
223
273
|
cdef bool pAvailable
|
|
224
|
-
|
|
274
|
+
cdef LIBFLIPRO_API success
|
|
275
|
+
with nogil:
|
|
276
|
+
success = FPROFrame_IsAvailable(self._handle, &pAvailable)
|
|
277
|
+
if success < 0:
|
|
225
278
|
raise ValueError('Could not fetch exposure status.')
|
|
226
279
|
return pAvailable
|
|
227
280
|
|
|
228
281
|
def get_sensor_temperature(self):
|
|
229
282
|
cdef int32_t pTemp
|
|
230
|
-
|
|
283
|
+
cdef LIBFLIPRO_API success
|
|
284
|
+
with nogil:
|
|
285
|
+
success = FPROCtrl_GetSensorTemperature(self._handle, &pTemp)
|
|
286
|
+
if success < 0:
|
|
231
287
|
raise ValueError('Could not fetch sensor temperature.')
|
|
232
288
|
return pTemp
|
|
233
289
|
|
|
234
290
|
def get_temperatures(self):
|
|
235
291
|
cdef double pAmbientTemp, pBaseTemp, pCoolerTemp
|
|
236
|
-
|
|
292
|
+
cdef LIBFLIPRO_API success
|
|
293
|
+
with nogil:
|
|
294
|
+
success = FPROCtrl_GetTemperatures(self._handle, &pAmbientTemp, &pBaseTemp, &pCoolerTemp)
|
|
295
|
+
if success < 0:
|
|
237
296
|
raise ValueError('Could not fetch temperatures.')
|
|
238
297
|
return pAmbientTemp, pBaseTemp, pCoolerTemp
|
|
239
298
|
|
|
240
299
|
def get_temperature_set_point(self):
|
|
241
300
|
cdef double pSetPoint
|
|
242
|
-
|
|
301
|
+
cdef LIBFLIPRO_API success
|
|
302
|
+
with nogil:
|
|
303
|
+
success = FPROCtrl_GetTemperatureSetPoint(self._handle, &pSetPoint)
|
|
304
|
+
if success < 0:
|
|
243
305
|
raise ValueError('Could not get setpoint temperature.')
|
|
244
306
|
return pSetPoint
|
|
245
307
|
|
|
246
308
|
def set_temperature_set_point(self, temp):
|
|
247
309
|
cdef double dblSetPoint = temp
|
|
248
|
-
|
|
310
|
+
cdef LIBFLIPRO_API success
|
|
311
|
+
with nogil:
|
|
312
|
+
success = FPROCtrl_SetTemperatureSetPoint(self._handle, dblSetPoint)
|
|
313
|
+
if success < 0:
|
|
249
314
|
raise ValueError('Could not fetch setpoint temperature.')
|
|
250
315
|
|
|
251
316
|
def get_cooler_duty_cycle(self):
|
|
252
317
|
cdef uint32_t pDutyCycle
|
|
253
|
-
|
|
318
|
+
cdef LIBFLIPRO_API success
|
|
319
|
+
with nogil:
|
|
320
|
+
success = FPROCtrl_GetCoolerDutyCycle(self._handle, &pDutyCycle)
|
|
321
|
+
if success < 0:
|
|
254
322
|
raise ValueError('Could not fetch cooler duty cycle.')
|
|
255
323
|
return pDutyCycle
|
|
256
324
|
|
|
257
325
|
def get_binning(self):
|
|
258
326
|
cdef uint32_t pXBin, pYBin
|
|
259
|
-
|
|
327
|
+
cdef LIBFLIPRO_API success
|
|
328
|
+
with nogil:
|
|
329
|
+
success = FPROSensor_GetBinning(self._handle, &pXBin, &pYBin)
|
|
330
|
+
if success < 0:
|
|
260
331
|
raise ValueError('Could not fetch binning.')
|
|
261
332
|
return pXBin, pYBin
|
|
262
333
|
|
|
263
334
|
def set_binning(self, x, y):
|
|
264
|
-
|
|
335
|
+
cdef uint32_t x_c = x
|
|
336
|
+
cdef uint32_t y_c = y
|
|
337
|
+
cdef LIBFLIPRO_API success
|
|
338
|
+
with nogil:
|
|
339
|
+
success = FPROSensor_SetBinning(self._handle, x_c, y_c)
|
|
340
|
+
if success < 0:
|
|
265
341
|
raise ValueError('Could not set binning.')
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Plan: Release the GIL around libflipro calls
|
|
2
|
+
|
|
3
|
+
Status: in progress
|
|
4
|
+
|
|
5
|
+
Tracks: https://github.com/pyobs/pyobs-flipro/issues/29
|
|
6
|
+
|
|
7
|
+
## Problem
|
|
8
|
+
|
|
9
|
+
A hung FLI Pro device freezes the whole module, including XMPP. `FliProCamera` already runs
|
|
10
|
+
every FLIPRO SDK call in a daemon thread bounded by `asyncio.wait_for(...)` via
|
|
11
|
+
`_run_blocking`/`_run_blocking_or_raise` (`pyobs_flipro/fliprocamera.py`) — the correct
|
|
12
|
+
mitigation for a blocking vendor SDK call made from an `async def` method. It doesn't actually
|
|
13
|
+
bound a hung call, because `libflipro.pxd` declares `FPROCam_Open`, `FPROCam_GetCameraList`,
|
|
14
|
+
`FPROFrame_GetVideoFrameUnpacked`, etc. without `nogil`. Cython calls into a non-`nogil` C
|
|
15
|
+
function while still holding the GIL, so when the call blocks (unresponsive device), the daemon
|
|
16
|
+
thread holds the GIL for the entire hang. The event loop thread cannot run *anything* on that
|
|
17
|
+
GIL, including the `asyncio.wait_for` timeout machinery meant to bound the call. The timeout
|
|
18
|
+
never fires; the module goes fully unresponsive (same shape as `pyobs/pyobs-fli#75`, fixed there
|
|
19
|
+
in `pyobs/pyobs-fli#76`).
|
|
20
|
+
|
|
21
|
+
## Decision
|
|
22
|
+
|
|
23
|
+
Mark the libflipro C functions `nogil` in `libflipro.pxd`, and wrap each call site in
|
|
24
|
+
`fliprodriver.pyx` in `with nogil:` so the GIL is actually released while the call runs. This
|
|
25
|
+
restores the daemon-thread timeout's ability to fire, since the event loop thread can run while
|
|
26
|
+
the SDK call blocks.
|
|
27
|
+
|
|
28
|
+
Considered and rejected: running FLIPRO calls in a subprocess. Same reasoning as
|
|
29
|
+
`pyobs/pyobs-fli#76` — a much larger change (IPC, serialization of frame buffers, process
|
|
30
|
+
lifecycle) for the same practical outcome. Revisit only if a `with nogil:` call still wedges
|
|
31
|
+
(e.g. the SDK deadlocks internally in a way that isn't a simple blocking wait).
|
|
32
|
+
|
|
33
|
+
## Design
|
|
34
|
+
|
|
35
|
+
### `libflipro.pxd`
|
|
36
|
+
|
|
37
|
+
Change the whole `cdef extern from "../lib/libflipro.h":` block to
|
|
38
|
+
`cdef extern from "../lib/libflipro.h" nogil:`. This marks every declared function `nogil` at
|
|
39
|
+
once, including ones not yet called from `fliprodriver.pyx`, so new call sites added later don't
|
|
40
|
+
silently regress. Safe for the whole block: libflipro is a pure hardware-I/O C library, none of
|
|
41
|
+
its functions take a Python object or call back into the interpreter.
|
|
42
|
+
|
|
43
|
+
### `fliprodriver.pyx`
|
|
44
|
+
|
|
45
|
+
`nogil` only changes what's *allowed* inside `with nogil:` — it does not by itself move existing
|
|
46
|
+
calls off the GIL. Every call site needs a `with nogil:` around the actual `FPRO*()`/`LIBFLIPRO_*`
|
|
47
|
+
call, and anything inside that block that isn't a C primitive has to move outside it first:
|
|
48
|
+
|
|
49
|
+
- **Typed-arg unboxing** (`set_image_area`'s `col_offset`/`row_offset`/`width`/`height`,
|
|
50
|
+
`set_exposure_time`'s `exptime_ns`, `set_binning`'s `x`/`y`): read into local `cdef` C
|
|
51
|
+
variables before the `with nogil:` block, since Python->C unboxing touches the GIL.
|
|
52
|
+
(`set_temperature_set_point` already hoisted `temp` into `cdef double dblSetPoint`.)
|
|
53
|
+
- **`self._handle` / `self._device`**: no change needed. They are C-typed (`cdef int32_t` /
|
|
54
|
+
`cdef FPRODEVICEINFO`) fields of a `cdef class`, so reading them inside `with nogil:` is a
|
|
55
|
+
direct field access, not a Python attribute lookup.
|
|
56
|
+
- **`read_exposure()`**: `frame_data`, `c_frame_size`, `buffers`, `stats` are all C locals; only
|
|
57
|
+
the `FPROFrame_GetVideoFrameUnpacked` and `FPROFrame_FreeUnpackedBuffers` calls need wrapping.
|
|
58
|
+
Buffer bookkeeping (`malloc`, `memcpy`, `free`) stays where it is — the `libc` declarations
|
|
59
|
+
are `nogil` anyway.
|
|
60
|
+
- **Results**: every call's return value is captured in a `cdef LIBFLIPRO_API success` local
|
|
61
|
+
inside the `with nogil:` block and checked after it, preserving the existing
|
|
62
|
+
`if success < 0: raise ValueError(...)` behavior.
|
|
63
|
+
|
|
64
|
+
Cython raises a compile-time error for any Python-object touch inside a `with nogil:` block, so
|
|
65
|
+
this is self-checking: if an extraction is missed, `cython` on `fliprodriver.pyx` fails before
|
|
66
|
+
any build/link step.
|
|
67
|
+
|
|
68
|
+
### `_wait_exposure()` in `fliprocamera.py`
|
|
69
|
+
|
|
70
|
+
No change needed here: the poll loop already runs `is_available()` inside a single
|
|
71
|
+
`_run_blocking_or_raise` call rather than polling per-tick on the event loop, so only the
|
|
72
|
+
underlying `FPROFrame_IsAvailable` call in `fliprodriver.pyx` needed the `nogil` wrapping.
|
|
73
|
+
|
|
74
|
+
## Verification
|
|
75
|
+
|
|
76
|
+
No existing test suite exercises the Cython extension (no way to run libflipro calls without
|
|
77
|
+
real hardware). Verification is:
|
|
78
|
+
|
|
79
|
+
1. `cython pyobs_flipro/fliprodriver.pyx -I pyobs_flipro` compiles clean (catches any missed
|
|
80
|
+
nogil extraction as a hard error, not just a lint).
|
|
81
|
+
2. Full `uv sync` (scikit-build-core/CMake) build succeeds, the generated C shows
|
|
82
|
+
`PyEval_SaveThread()`/`PyEval_RestoreThread()` around every SDK call, and the resulting
|
|
83
|
+
extension imports.
|
|
84
|
+
3. `pytest tests` passes (regression: `_run_blocking`/`_run_blocking_or_raise` wrappers and
|
|
85
|
+
constructor/setter behavior unchanged).
|
|
86
|
+
4. Manual read-through confirming every `FPRO*`/`LIBFLIPRO_*` call site in the diff is inside a
|
|
87
|
+
`with nogil:` block, and that nothing added to `libflipro.pxd`'s `nogil` block passes a Python
|
|
88
|
+
object by reference to a C function that could retain/mutate it — none of the current API does.
|
|
89
|
+
|
|
90
|
+
No hardware-in-the-loop test is possible from here; actual freeze recovery on a hung FLI Pro
|
|
91
|
+
device can only be confirmed on-site.
|
|
92
|
+
|
|
93
|
+
## Implementation checklist
|
|
94
|
+
|
|
95
|
+
- [x] `libflipro.pxd`: add `nogil` to the `cdef extern from "../lib/libflipro.h":` line.
|
|
96
|
+
- [x] `fliprodriver.pyx`: wrap every `FPRO*`/`LIBFLIPRO_*` call site in `with nogil:`, hoisting
|
|
97
|
+
typed-arg reads above the block as described in Design.
|
|
98
|
+
- [x] `cython pyobs_flipro/fliprodriver.pyx -I pyobs_flipro` compiles with no errors.
|
|
99
|
+
- [x] Full build (`uv sync`) succeeds; the generated C releases the GIL around each SDK call and
|
|
100
|
+
the extension imports.
|
|
101
|
+
- [x] `pytest tests` passes.
|
|
102
|
+
- [x] Open a PR against `develop` (matches this repo's branch convention — dependabot/feature
|
|
103
|
+
PRs land on `develop`, which then gets version-bumped into `main`). Opened as #36.
|
|
104
|
+
- [ ] Update this doc's `Status:` to `implemented` once merged.
|
|
@@ -82,6 +82,15 @@ async def test_run_blocking_times_out() -> None:
|
|
|
82
82
|
await asyncio.sleep(0.05)
|
|
83
83
|
|
|
84
84
|
|
|
85
|
+
@pytest.mark.asyncio
|
|
86
|
+
async def test_run_blocking_reraises() -> None:
|
|
87
|
+
def boom() -> None:
|
|
88
|
+
raise ValueError("boom")
|
|
89
|
+
|
|
90
|
+
with pytest.raises(ValueError):
|
|
91
|
+
await FliProCamera._run_blocking(boom)
|
|
92
|
+
|
|
93
|
+
|
|
85
94
|
@pytest.mark.asyncio
|
|
86
95
|
async def test_run_blocking_or_raise_returns_value() -> None:
|
|
87
96
|
camera = FliProCamera(-20.0)
|
|
@@ -2320,7 +2320,7 @@ wheels = [
|
|
|
2320
2320
|
|
|
2321
2321
|
[[package]]
|
|
2322
2322
|
name = "pyobs-core"
|
|
2323
|
-
version = "2.0.0.
|
|
2323
|
+
version = "2.0.0.dev91"
|
|
2324
2324
|
source = { registry = "https://pypi.org/simple" }
|
|
2325
2325
|
dependencies = [
|
|
2326
2326
|
{ name = "aiohttp" },
|
|
@@ -2352,9 +2352,9 @@ dependencies = [
|
|
|
2352
2352
|
{ name = "tenacity" },
|
|
2353
2353
|
{ name = "typing-extensions" },
|
|
2354
2354
|
]
|
|
2355
|
-
sdist = { url = "https://files.pythonhosted.org/packages/
|
|
2355
|
+
sdist = { url = "https://files.pythonhosted.org/packages/60/62/d1fd0cf3151bfea63d84f6b54347be5791e91b5deee519cd34e64f9f1738/pyobs_core-2.0.0.dev91.tar.gz", hash = "sha256:4fe3e77fee9ddedbeba58414bd4931afbf5172abd42a589440865ea401f1aa47", size = 367177, upload-time = "2026-08-21T07:40:29.948Z" }
|
|
2356
2356
|
wheels = [
|
|
2357
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2357
|
+
{ url = "https://files.pythonhosted.org/packages/48/24/e4b2e9b5550561832db50bbcb18ecaf6b18df245bce6ba9926cb9e925760/pyobs_core-2.0.0.dev91-py3-none-any.whl", hash = "sha256:bc5a08c3eca102c460938b590a3183453e101950f4ca1250e0bc974c5e6caa86", size = 590331, upload-time = "2026-08-21T07:40:28.132Z" },
|
|
2358
2358
|
]
|
|
2359
2359
|
|
|
2360
2360
|
[package.optional-dependencies]
|
|
@@ -2366,7 +2366,7 @@ gui = [
|
|
|
2366
2366
|
|
|
2367
2367
|
[[package]]
|
|
2368
2368
|
name = "pyobs-flipro"
|
|
2369
|
-
version = "2.0.0.
|
|
2369
|
+
version = "2.0.0.dev11"
|
|
2370
2370
|
source = { editable = "." }
|
|
2371
2371
|
dependencies = [
|
|
2372
2372
|
{ name = "astropy" },
|
|
@@ -2728,27 +2728,27 @@ wheels = [
|
|
|
2728
2728
|
|
|
2729
2729
|
[[package]]
|
|
2730
2730
|
name = "ruff"
|
|
2731
|
-
version = "0.16.
|
|
2732
|
-
source = { registry = "https://pypi.org/simple" }
|
|
2733
|
-
sdist = { url = "https://files.pythonhosted.org/packages/
|
|
2734
|
-
wheels = [
|
|
2735
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2736
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2737
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2738
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2739
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2740
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2741
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2742
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2743
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2744
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2745
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2746
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2747
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2748
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2749
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2750
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2751
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
2731
|
+
version = "0.16.4"
|
|
2732
|
+
source = { registry = "https://pypi.org/simple" }
|
|
2733
|
+
sdist = { url = "https://files.pythonhosted.org/packages/00/8f/d8074b1f25e003164087a8bfe79a0f1a3945135764dbb6aaab04103dcaf9/ruff-0.16.4.tar.gz", hash = "sha256:13171aa9d9af2240ee3504e639de73122c67e74036de5ba2e1d01422cd17e3dc", size = 4899731, upload-time = "2026-08-20T17:43:59.196Z" }
|
|
2734
|
+
wheels = [
|
|
2735
|
+
{ url = "https://files.pythonhosted.org/packages/ff/80/779895ef584e089d22f2c6df0d0e99a65ec2df0805f1fffd439415b8c1f0/ruff-0.16.4-py3-none-linux_armv6l.whl", hash = "sha256:df4075f71ddac40b9934af60c3ec8a53047dd5a5fdc43224e6e4e8e9a27cb6f7", size = 10006909, upload-time = "2026-08-20T17:43:16.888Z" },
|
|
2736
|
+
{ url = "https://files.pythonhosted.org/packages/a9/e6/f553199b5e8927a05cb5c422d921fd0656b29ab976e91c44802107c6b0da/ruff-0.16.4-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:0c95538517af68004306b0fb3214ff2f2af67a65092aee77cd9eb86db6656604", size = 10240201, upload-time = "2026-08-20T17:43:19.337Z" },
|
|
2737
|
+
{ url = "https://files.pythonhosted.org/packages/1c/70/4a6dc4bb34da4dee35e30f09bbd1bfbdd26f33b62fb9b8df31f08a199cd2/ruff-0.16.4-py3-none-macosx_11_0_arm64.whl", hash = "sha256:963f83df8e69e575b64d67dd447ebbc917db41a14bf38d4593a4183e7aaa8255", size = 9835122, upload-time = "2026-08-20T17:43:21.708Z" },
|
|
2738
|
+
{ url = "https://files.pythonhosted.org/packages/24/12/c6e22d686372c15bcb7af99831f1a1be96df696491babf4f24e4f942c527/ruff-0.16.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:32a5057c7ff3f6e6480a48fccfb3a412a690f48a3d03ac5cf08177d6c2da3ade", size = 9977162, upload-time = "2026-08-20T17:43:24.236Z" },
|
|
2739
|
+
{ url = "https://files.pythonhosted.org/packages/46/49/72b10ec912f5ab5854992eaf7aa7cd36729b6937d9dc4e0fb41b3bf428ec/ruff-0.16.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:b3dce8d9b0c57c265b91885a66a567d8ea1372e8eb4e250fa8e5e3f579e99cff", size = 9829789, upload-time = "2026-08-20T17:43:26.966Z" },
|
|
2740
|
+
{ url = "https://files.pythonhosted.org/packages/fa/80/0f30e32e7f6ee26edc39075502db9d368d788a44a79b55f763eb4ab03796/ruff-0.16.4-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7dc651db49283c69f8e72c834eec4fe5573e4c646856aebece0ce385dceb2a80", size = 10527949, upload-time = "2026-08-20T17:43:29.384Z" },
|
|
2741
|
+
{ url = "https://files.pythonhosted.org/packages/52/3d/86e8ad3542169e56cac3859a343afdb9df2ad54d35a59ce1e67baee83421/ruff-0.16.4-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3817b87dbcabc92f13b05019257c5b89b5b4d51b5fb20f56fb5235ceb723cd07", size = 11333695, upload-time = "2026-08-20T17:43:31.872Z" },
|
|
2742
|
+
{ url = "https://files.pythonhosted.org/packages/d0/16/481c29b380c20a0054a8261066665e1b3488e23636c49d0a43e75975b9bb/ruff-0.16.4-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:e9fce1499134b2c8c68e5166f95705a5812062bb93aacc5f9873bb1a27084bc7", size = 10727741, upload-time = "2026-08-20T17:43:34.596Z" },
|
|
2743
|
+
{ url = "https://files.pythonhosted.org/packages/5e/b6/56bc0b8cf45b54b28b3a5e6381c8945d51b5b18adf659454c32295209a31/ruff-0.16.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f2d812e482f5a7e02eee26cd73d2a37ebbdf47d795ea63ba1b89110ae93e9fb3", size = 10286522, upload-time = "2026-08-20T17:43:37.288Z" },
|
|
2744
|
+
{ url = "https://files.pythonhosted.org/packages/e8/8b/b345b4fb110f2fbe2bd31eabd271e5e8b3b7e4ee6c0e02f2dc6be78db000/ruff-0.16.4-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:6baaf984aa7976edf93d3b627fe2d1d22ee94bbca05fa6f90fc76d73924e3454", size = 10584182, upload-time = "2026-08-20T17:43:39.984Z" },
|
|
2745
|
+
{ url = "https://files.pythonhosted.org/packages/29/e5/827b34041c35f58774a9681a4213994c164fc987800f4dddabcf451da0bf/ruff-0.16.4-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:bdfcf0b28662eb890372d50f92c283bb94e67e7635ed93c7fd533970acff7b2b", size = 10134195, upload-time = "2026-08-20T17:43:42.351Z" },
|
|
2746
|
+
{ url = "https://files.pythonhosted.org/packages/0f/10/d0bffcdd6729b87afc82ba0ef377173356a7dc8e972f5179968cf2fdf98c/ruff-0.16.4-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:b66b02cb9b04f537643cadf5768e5f98dc461890d530cb67113d71c8c76e605d", size = 9825821, upload-time = "2026-08-20T17:43:44.532Z" },
|
|
2747
|
+
{ url = "https://files.pythonhosted.org/packages/f5/32/0db2a863b796ca62d83e92a07a3ccf00921b14db02059347576a2fda3d4b/ruff-0.16.4-py3-none-musllinux_1_2_i686.whl", hash = "sha256:8528bf9a4b291a60bf02ea453511e8ce6215bd2b982ee80405b66b008b6c30a0", size = 10267658, upload-time = "2026-08-20T17:43:46.989Z" },
|
|
2748
|
+
{ url = "https://files.pythonhosted.org/packages/b2/a0/fbdeb59e48c6261f523e56c8f12e9c08fbe693786595cc7e3959207a9232/ruff-0.16.4-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:fbd85d2875fdd67e833213a651f613bbf25303abf6aa822a5121f4531195678d", size = 10697071, upload-time = "2026-08-20T17:43:49.891Z" },
|
|
2749
|
+
{ url = "https://files.pythonhosted.org/packages/aa/28/0c6dd865859c6d17bc8ccc34cb72b0e02d6c7eb25e8a1e22b5bea681e2c0/ruff-0.16.4-py3-none-win32.whl", hash = "sha256:312769988007aaeb8e189b443ccdd03c0e6374489e053467be6d96518ebff76e", size = 10021687, upload-time = "2026-08-20T17:43:52.281Z" },
|
|
2750
|
+
{ url = "https://files.pythonhosted.org/packages/a3/03/e724450f621698117f9aa6dd241c94d0274ae96781378dc86745ae29f0e7/ruff-0.16.4-py3-none-win_amd64.whl", hash = "sha256:05d9d27a18c4bcbefada602480ec9e01e0bc949d432e0ced5df77edac195919c", size = 10567657, upload-time = "2026-08-20T17:43:54.78Z" },
|
|
2751
|
+
{ url = "https://files.pythonhosted.org/packages/0e/fe/da8b9e1347696bb22120b77280ec5ce25d500ca5cb39d5ad6e5c18de19c1/ruff-0.16.4-py3-none-win_arm64.whl", hash = "sha256:a3a61621c9b6f6a89573e938a080e648f1695baa3f58570a3a707bc51ff65a21", size = 10451579, upload-time = "2026-08-20T17:43:57.135Z" },
|
|
2752
2752
|
]
|
|
2753
2753
|
|
|
2754
2754
|
[[package]]
|