Linux support for the external Python client#2
Open
pskeshu wants to merge 1 commit into
Open
Conversation
The external Python API previously assumed Windows transports (named pipe + named file mapping). This makes both the client and the server side of the local API cross-platform, so a running ScopeOne can be driven from Python on Linux. Windows behaviour is unchanged (guarded by _WIN32 / os.name). Server (src/ScopeOneLocalApiServer.cpp/.h): - Platform-aware control endpoint: keep the Windows named pipe, use a plain QLocalServer name on Unix (resolves to <tempdir>/ScopeOne.Api.local). - Frame export on Linux via a POSIX shared-memory object (shm_open + mmap), visible to external clients at /dev/shm/ScopeOne.Api.frame; cleaned up with munmap/close/shm_unlink on shutdown. - Frame-export readiness check is platform-specific: the Windows handle+view check is left unchanged; Linux checks the mapped view (there is no Windows handle there). Client (ScopeOneCore/python/scopeone): - Split the transport: Windows keeps the pywin32 pipe + tagname mmap; Unix uses an AF_UNIX socket and reads frames by mmapping /dev/shm. Protocol and frame layout are identical, so the public API and shm.py are unchanged. - pyproject: make pywin32 a Windows-only dependency and add the Linux classifier. Verified on Linux against the demo camera: connect -> load_config -> preview -> record -> session.frame() returns a (512,512) uint16 numpy array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #1. That PR made the desktop app build and run on Linux; this one
makes the external Python API (
ScopeOneCore/python/scopeone) work there too,so a running ScopeOne can be driven from Python on Linux. Windows behaviour is
unchanged — every platform-specific path is guarded by
_WIN32(C++) oros.name(Python).The control protocol (length-prefixed JSON) and the shared-frame layout are
already platform-neutral; only the two transports were Windows-only.
What's in this PR (4 files)
Control channel —
src/ScopeOneLocalApiServer.cppQLocalServerdropsverbatim into a socket path on Unix. Made it platform-aware: keep the named
pipe on Windows, use a plain
ScopeOne.Api.localname on Unix (Qt resolves itto a unix socket under the temp dir).
Frame export —
src/ScopeOneLocalApiServer.cpp/.h(
CreateFileMapping) that the client opens by name. This adds the Linuxequivalent: a POSIX shared-memory object (
shm_open+mmap) at/dev/shm/ScopeOne.Api.frame, cleaned up withmunmap/shm_unlinkonshutdown.
Python client —
ScopeOneCore/python/scopeonenamed pipe +
mmap(tagname=...); Linux uses anAF_UNIXsocket and readsframes by
mmap-ing the/dev/shmobject. The public API, the requestprotocol, and
shm.pyare unchanged.pyproject.toml:pywin32is now a Windows-only dependency, and the Linuxclassifier is added.
Verification
Tested end-to-end against the demo camera on Linux (Manjaro, Qt 6.11, Python
3.14):
No extra Python dependencies on Linux — the client uses only the standard
library (
socket,mmap).Scope
a Windows check would be welcome).