neutralino-python 0.1.0rc1__py3-none-any.whl
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.
- neutralino/__init__.py +88 -0
- neutralino/_catalog.py +297 -0
- neutralino/_data/LICENSE.neutralino-js-client +21 -0
- neutralino/_data/LICENSE.neutralinojs +1066 -0
- neutralino/_data/docs/cli.md +315 -0
- neutralino/_data/docs/custom-components.md +107 -0
- neutralino/_data/docs/custom-frontends.md +80 -0
- neutralino/_data/docs/desktop-helpers.md +296 -0
- neutralino/_data/docs/guide.md +131 -0
- neutralino/_data/docs/llms-full.txt +3921 -0
- neutralino/_data/docs/llms.txt +43 -0
- neutralino/_data/docs/manifests/components.json +20128 -0
- neutralino/_data/docs/manifests/examples.json +52 -0
- neutralino/_data/docs/manifests/native.json +3024 -0
- neutralino/_data/docs/manifests/schema.json +43 -0
- neutralino/_data/docs/manual-checklist.md +189 -0
- neutralino/_data/docs/packaging.md +252 -0
- neutralino/_data/docs/performance.md +15 -0
- neutralino/_data/docs/platforms.md +15 -0
- neutralino/_data/docs/reference/components.md +1685 -0
- neutralino/_data/docs/reference/native.md +148 -0
- neutralino/_data/docs/security.md +60 -0
- neutralino/_data/docs/ui.md +249 -0
- neutralino/_data/docs/updates.md +366 -0
- neutralino/_data/examples/README.md +6 -0
- neutralino/_data/examples/crud/README.md +36 -0
- neutralino/_data/examples/crud/app.py +243 -0
- neutralino/_data/examples/dashboard/README.md +36 -0
- neutralino/_data/examples/dashboard/app.py +367 -0
- neutralino/_data/examples/editor/README.md +35 -0
- neutralino/_data/examples/editor/app.py +190 -0
- neutralino/_data/examples/file-manager/README.md +40 -0
- neutralino/_data/examples/file-manager/app.py +120 -0
- neutralino/_data/examples/file-manager/frontend/index.html +20 -0
- neutralino/_data/examples/file-manager/frontend/main.js +55 -0
- neutralino/_data/examples/file-manager/frontend/neutralino.js +1 -0
- neutralino/_data/examples/file-manager/frontend/python-bridge.d.ts +207 -0
- neutralino/_data/examples/file-manager/frontend/python-bridge.mjs +854 -0
- neutralino/_data/examples/file-manager/frontend/style.css +4 -0
- neutralino/_data/examples/hybrid/README.md +48 -0
- neutralino/_data/examples/hybrid/app.py +80 -0
- neutralino/_data/examples/hybrid/components/counter.mjs +37 -0
- neutralino/_data/examples/hybrid/components/widget.mjs +23 -0
- neutralino/_data/examples/hybrid/styles.css +21 -0
- neutralino/_data/examples/hybrid/widget/package.json +20 -0
- neutralino/_data/examples/hybrid/widget/src/Widget.jsx +25 -0
- neutralino/_data/examples/hybrid/widget/vite.config.mjs +19 -0
- neutralino/_data/examples/monitor/README.md +36 -0
- neutralino/_data/examples/monitor/app.py +375 -0
- neutralino/_data/examples/react/README.md +90 -0
- neutralino/_data/examples/react/app.py +68 -0
- neutralino/_data/examples/react/frontend/.gitignore +5 -0
- neutralino/_data/examples/react/frontend/index.html +17 -0
- neutralino/_data/examples/react/frontend/package-lock.json +1232 -0
- neutralino/_data/examples/react/frontend/package.json +25 -0
- neutralino/_data/examples/react/frontend/scripts/prepare-bridge.mjs +49 -0
- neutralino/_data/examples/react/frontend/src/App.tsx +157 -0
- neutralino/_data/examples/react/frontend/src/backend.ts +21 -0
- neutralino/_data/examples/react/frontend/src/calls.test.ts +206 -0
- neutralino/_data/examples/react/frontend/src/calls.ts +306 -0
- neutralino/_data/examples/react/frontend/src/globals.d.ts +14 -0
- neutralino/_data/examples/react/frontend/src/hooks.ts +45 -0
- neutralino/_data/examples/react/frontend/src/main.tsx +13 -0
- neutralino/_data/examples/react/frontend/src/styles.css +11 -0
- neutralino/_data/examples/react/frontend/tsconfig.json +18 -0
- neutralino/_data/examples/react/frontend/vite.config.ts +9 -0
- neutralino/_data/examples/settings/README.md +38 -0
- neutralino/_data/examples/settings/app.py +440 -0
- neutralino/_data/examples/updater/.gitignore +2 -0
- neutralino/_data/examples/updater/README.md +82 -0
- neutralino/_data/examples/updater/app.py +160 -0
- neutralino/_data/examples/updater/app.toml +21 -0
- neutralino/_data/examples/updater/demo.py +107 -0
- neutralino/_data/examples/updater/requirements.txt +2 -0
- neutralino/_data/examples/updater/sources/github-private.toml +21 -0
- neutralino/_data/examples/updater/sources/github-public.toml +21 -0
- neutralino/_data/examples/vanilla/README.md +35 -0
- neutralino/_data/examples/vanilla/app.py +46 -0
- neutralino/_data/examples/vanilla/frontend/index.html +17 -0
- neutralino/_data/examples/vanilla/frontend/main.js +29 -0
- neutralino/_data/examples/vanilla/frontend/neutralino.js +1 -0
- neutralino/_data/examples/vanilla/frontend/python-bridge.d.ts +207 -0
- neutralino/_data/examples/vanilla/frontend/python-bridge.mjs +854 -0
- neutralino/_data/examples/vanilla/frontend/style.css +4 -0
- neutralino/_data/explorer/app.py +1328 -0
- neutralino/_data/explorer/catalogue.json +48179 -0
- neutralino/_data/explorer/explorer_previews.py +247 -0
- neutralino/_data/explorer/sources/native/always_on_top.py +55 -0
- neutralino/_data/explorer/sources/native/binary.py +125 -0
- neutralino/_data/explorer/sources/native/borderless.py +99 -0
- neutralino/_data/explorer/sources/native/broadcast.py +90 -0
- neutralino/_data/explorer/sources/native/config.py +78 -0
- neutralino/_data/explorer/sources/native/controls.py +140 -0
- neutralino/_data/explorer/sources/native/directory.py +163 -0
- neutralino/_data/explorer/sources/native/displays.py +75 -0
- neutralino/_data/explorer/sources/native/env.py +98 -0
- neutralino/_data/explorer/sources/native/events.py +124 -0
- neutralino/_data/explorer/sources/native/exec_command.py +79 -0
- neutralino/_data/explorer/sources/native/folder.py +70 -0
- neutralino/_data/explorer/sources/native/icon_badge.py +101 -0
- neutralino/_data/explorer/sources/native/image.py +119 -0
- neutralino/_data/explorer/sources/native/lifecycle.py +99 -0
- neutralino/_data/explorer/sources/native/locale.py +70 -0
- neutralino/_data/explorer/sources/native/main_menu.py +103 -0
- neutralino/_data/explorer/sources/native/message_box.py +101 -0
- neutralino/_data/explorer/sources/native/mouse.py +70 -0
- neutralino/_data/explorer/sources/native/multi_window.py +134 -0
- neutralino/_data/explorer/sources/native/notification.py +74 -0
- neutralino/_data/explorer/sources/native/open_external.py +81 -0
- neutralino/_data/explorer/sources/native/open_file.py +102 -0
- neutralino/_data/explorer/sources/native/paths.py +77 -0
- neutralino/_data/explorer/sources/native/print_snapshot.py +84 -0
- neutralino/_data/explorer/sources/native/read_write.py +192 -0
- neutralino/_data/explorer/sources/native/resources.py +110 -0
- neutralino/_data/explorer/sources/native/save_file.py +101 -0
- neutralino/_data/explorer/sources/native/server_mount.py +106 -0
- neutralino/_data/explorer/sources/native/sound.py +84 -0
- neutralino/_data/explorer/sources/native/spawn_process.py +128 -0
- neutralino/_data/explorer/sources/native/states.py +122 -0
- neutralino/_data/explorer/sources/native/stats_permissions.py +147 -0
- neutralino/_data/explorer/sources/native/storage.py +108 -0
- neutralino/_data/explorer/sources/native/system_info.py +115 -0
- neutralino/_data/explorer/sources/native/text.py +133 -0
- neutralino/_data/explorer/sources/native/trash.py +98 -0
- neutralino/_data/explorer/sources/native/tray.py +109 -0
- neutralino/_data/explorer/sources/native/watcher.py +167 -0
- neutralino/_data/explorer/sources/patterns/content_blocks.py +119 -0
- neutralino/_data/explorer/sources/patterns/dynamic_dashboard.py +121 -0
- neutralino/_data/explorer/sources/patterns/dynamic_form.py +120 -0
- neutralino/_data/explorer/sources/patterns/dynamic_table.py +109 -0
- neutralino/_data/explorer/sources/patterns/error_reporting.mjs +24 -0
- neutralino/_data/explorer/sources/patterns/error_reporting.py +124 -0
- neutralino/_data/explorer/sources/patterns/errors_timeouts.py +108 -0
- neutralino/_data/explorer/sources/patterns/feature_flags.py +99 -0
- neutralino/_data/explorer/sources/patterns/file_drop.py +126 -0
- neutralino/_data/explorer/sources/patterns/http_from_python.py +152 -0
- neutralino/_data/explorer/sources/patterns/keyboard_shortcuts.py +153 -0
- neutralino/_data/explorer/sources/patterns/live_config_reload.py +160 -0
- neutralino/_data/explorer/sources/patterns/logging.py +184 -0
- neutralino/_data/explorer/sources/patterns/long_tasks.py +121 -0
- neutralino/_data/explorer/sources/patterns/multi_window_sync.py +68 -0
- neutralino/_data/explorer/sources/patterns/navigation_from_backend.py +109 -0
- neutralino/_data/explorer/sources/patterns/onboarding.py +123 -0
- neutralino/_data/explorer/sources/patterns/optimistic_updates.py +89 -0
- neutralino/_data/explorer/sources/patterns/persistence.py +114 -0
- neutralino/_data/explorer/sources/patterns/python_calls_page.mjs +10 -0
- neutralino/_data/explorer/sources/patterns/python_calls_page.py +64 -0
- neutralino/_data/explorer/sources/patterns/python_push.py +84 -0
- neutralino/_data/explorer/sources/patterns/recurring_events.py +114 -0
- neutralino/_data/explorer/sources/patterns/roles_permissions.py +104 -0
- neutralino/_data/explorer/sources/patterns/scheduled_jobs.py +194 -0
- neutralino/_data/explorer/sources/patterns/settings_page.py +165 -0
- neutralino/_data/explorer/sources/patterns/sqlite.py +181 -0
- neutralino/_data/explorer/sources/patterns/streaming.py +102 -0
- neutralino/_data/explorer/sources/patterns/texts_i18n.py +81 -0
- neutralino/_data/explorer/sources/patterns/theme_from_backend.py +86 -0
- neutralino/_data/explorer/sources/patterns/updater.py +232 -0
- neutralino/_data/explorer/sources/workspace/calendar/app.py +547 -0
- neutralino/_data/explorer/sources/workspace/customers/app.py +467 -0
- neutralino/_data/explorer/sources/workspace/dashboard/README.md +36 -0
- neutralino/_data/explorer/sources/workspace/dashboard/app.py +367 -0
- neutralino/_data/explorer/sources/workspace/documents/app.py +511 -0
- neutralino/_data/explorer/sources/workspace/inbox/app.py +439 -0
- neutralino/_data/explorer/sources/workspace/orders/app.py +491 -0
- neutralino/_data/explorer/sources/workspace/reports/app.py +386 -0
- neutralino/_data/explorer/sources/workspace/settings/README.md +38 -0
- neutralino/_data/explorer/sources/workspace/settings/app.py +440 -0
- neutralino/_data/explorer/sources/workspace/system/README.md +36 -0
- neutralino/_data/explorer/sources/workspace/system/app.py +375 -0
- neutralino/_data/explorer/sources/workspace/tasks/app.py +462 -0
- neutralino/_data/renderer/LICENSES/@babel__runtime@7.29.17/LICENSE +22 -0
- neutralino/_data/renderer/LICENSES/@codemirror__autocomplete@6.20.4/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__commands@6.11.2/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__lang-css@6.3.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__lang-html@6.4.12/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__lang-javascript@6.2.5/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__lang-json@6.0.2/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__lang-markdown@6.5.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__lang-python@6.2.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__lang-sql@6.10.0/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__lang-yaml@6.1.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__language@6.13.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__search@6.7.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__state@6.7.6/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@codemirror__view@6.44.2/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@dnd-kit__accessibility@3.1.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@dnd-kit__core@6.3.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@dnd-kit__sortable@10.0.0/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@dnd-kit__utilities@3.2.2/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@emoji-mart__data@1.2.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@floating-ui__core@1.8.0/LICENSE +20 -0
- neutralino/_data/renderer/LICENSES/@floating-ui__dom@1.8.0/LICENSE +20 -0
- neutralino/_data/renderer/LICENSES/@floating-ui__react-dom@2.1.9/LICENSE +20 -0
- neutralino/_data/renderer/LICENSES/@floating-ui__react@0.27.20/LICENSE +20 -0
- neutralino/_data/renderer/LICENSES/@floating-ui__utils@0.2.12/LICENSE +20 -0
- neutralino/_data/renderer/LICENSES/@lezer__common@1.5.7/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@lezer__css@1.3.9/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@lezer__highlight@1.2.5/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@lezer__html@1.3.13/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@lezer__javascript@1.5.7/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@lezer__json@1.0.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@lezer__lr@1.4.13/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@lezer__markdown@1.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@lezer__python@1.1.21/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@lezer__yaml@1.0.4/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__carousel@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__charts@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__code-highlight@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__core@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__dates@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__dropzone@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__emoji@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__hooks@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__lightbox@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__notifications@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__nprogress@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__schedule@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__spotlight@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__store@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@mantine__tiptap@9.8.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@marijn__find-cluster-break@1.0.4/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@reduxjs__toolkit@2.16.0/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@tabler__icons-react@3.55.0/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@tanstack__react-virtual@3.14.32/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@tanstack__virtual-core@3.19.17/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__core@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-blockquote@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-bold@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-code-block@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-code@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-document@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-hard-break@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-heading@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-horizontal-rule@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-italic@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-link@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-list@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-paragraph@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-strike@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-text@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extension-underline@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__extensions@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__react@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/@tiptap__starter-kit@3.35.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/attr-accept@4.0.1/LICENSE +22 -0
- neutralino/_data/renderer/LICENSES/clsx@2.1.1/license +9 -0
- neutralino/_data/renderer/LICENSES/crelt@1.0.7/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/d3-array@3.2.5/LICENSE +13 -0
- neutralino/_data/renderer/LICENSES/d3-color@3.1.1/LICENSE +13 -0
- neutralino/_data/renderer/LICENSES/d3-format@3.1.3/LICENSE +13 -0
- neutralino/_data/renderer/LICENSES/d3-interpolate@3.0.2/LICENSE +13 -0
- neutralino/_data/renderer/LICENSES/d3-path@3.1.1/LICENSE +13 -0
- neutralino/_data/renderer/LICENSES/d3-scale@4.0.3/LICENSE +13 -0
- neutralino/_data/renderer/LICENSES/d3-shape@3.2.1/LICENSE +13 -0
- neutralino/_data/renderer/LICENSES/d3-time-format@4.1.1/LICENSE +13 -0
- neutralino/_data/renderer/LICENSES/d3-time@3.1.1/LICENSE +13 -0
- neutralino/_data/renderer/LICENSES/dayjs@1.11.23/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/decimal.js-light@2.5.1/LICENCE.md +23 -0
- neutralino/_data/renderer/LICENSES/diff@9.0.0/LICENSE +29 -0
- neutralino/_data/renderer/LICENSES/dompurify@3.5.1/LICENSE +202 -0
- neutralino/_data/renderer/LICENSES/dompurify@3.5.1/LICENSE-MPL +373 -0
- neutralino/_data/renderer/LICENSES/embla-carousel-react@8.6.0/MIT-embla-carousel.txt +21 -0
- neutralino/_data/renderer/LICENSES/embla-carousel-reactive-utils@8.6.0/MIT-embla-carousel.txt +21 -0
- neutralino/_data/renderer/LICENSES/embla-carousel@8.6.0/MIT-embla-carousel.txt +21 -0
- neutralino/_data/renderer/LICENSES/es-toolkit@1.53.2/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/es-toolkit@1.53.2/NOTICE +39 -0
- neutralino/_data/renderer/LICENSES/eventemitter3@5.0.4/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/fast-equals@5.4.7/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/file-selector@5.0.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/get-nonce@1.0.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/immer@11.2.14/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/linkifyjs@4.4.0/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/marked@18.4.0/LICENSE +44 -0
- neutralino/_data/renderer/LICENSES/neutralino.js@6.11.0/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/orderedmap@2.1.1/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/packages.json +1838 -0
- neutralino/_data/renderer/LICENSES/prosemirror-commands@1.7.2/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/prosemirror-dropcursor@1.8.4/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/prosemirror-gapcursor@1.4.1/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/prosemirror-history@1.5.2/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/prosemirror-keymap@1.2.3/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/prosemirror-model@1.25.13/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/prosemirror-schema-list@1.6.1/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/prosemirror-state@1.4.4/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/prosemirror-transform@1.12.7/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/prosemirror-view@1.44.0/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/react-dom@19.3.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/react-dropzone@20.1.4/LICENSE +22 -0
- neutralino/_data/renderer/LICENSES/react-is@19.3.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/react-number-format@5.4.5/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/react-redux@9.3.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/react-remove-scroll-bar@2.3.8/MIT-react-remove-scroll-bar.txt +21 -0
- neutralino/_data/renderer/LICENSES/react-remove-scroll@2.7.2/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/react-style-singleton@2.2.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/react-transition-group@4.4.5/LICENSE +30 -0
- neutralino/_data/renderer/LICENSES/react@19.3.1/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/recharts@3.11.3/LICENSE +22 -0
- neutralino/_data/renderer/LICENSES/redux-thunk@3.1.0/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/redux@5.0.1/LICENSE.md +21 -0
- neutralino/_data/renderer/LICENSES/reselect@5.2.0/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/rolldown@1.3.4/LICENSE +25 -0
- neutralino/_data/renderer/LICENSES/rope-sequence@1.3.4/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/rrule@2.8.1/LICENCE +65 -0
- neutralino/_data/renderer/LICENSES/scheduler@0.28.0/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/style-mod@4.1.5/LICENSE +19 -0
- neutralino/_data/renderer/LICENSES/tiny-invariant@1.3.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/tslib@2.9.1/LICENSE.txt +12 -0
- neutralino/_data/renderer/LICENSES/use-callback-ref@1.3.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/use-sidecar@1.1.3/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/use-sync-external-store@1.7.0/LICENSE +21 -0
- neutralino/_data/renderer/LICENSES/victory-vendor@38.1.1/LICENSE.txt +150 -0
- neutralino/_data/renderer/LICENSES/vite@8.4.1/LICENSE.md +2320 -0
- neutralino/_data/renderer/LICENSES/w3c-keyname@2.2.8/LICENSE +19 -0
- neutralino/_data/renderer/assets/IconGripVertical-C2NUKJAE.js +1 -0
- neutralino/_data/renderer/assets/carousel-D1j1SkWR.css +1 -0
- neutralino/_data/renderer/assets/carousel-DHnOKa8c.js +1 -0
- neutralino/_data/renderer/assets/chunk-CCkLOSkX.css +1 -0
- neutralino/_data/renderer/assets/chunk-CLVygP7p.js +9 -0
- neutralino/_data/renderer/assets/codehighlight-CXJaU0yv.js +10 -0
- neutralino/_data/renderer/assets/codehighlight-THJMNDh8.css +1 -0
- neutralino/_data/renderer/assets/codemirror-DX0MbxKq.js +2 -0
- neutralino/_data/renderer/assets/css-BotC7byr.js +1 -0
- neutralino/_data/renderer/assets/dist-3kB5bJpS.js +23 -0
- neutralino/_data/renderer/assets/dist-6zrr4MrK.js +1 -0
- neutralino/_data/renderer/assets/dist-Beotrn8G.js +1 -0
- neutralino/_data/renderer/assets/dist-CCJHv8n0.js +11 -0
- neutralino/_data/renderer/assets/dist-CdYA9or5.js +1 -0
- neutralino/_data/renderer/assets/dist-D2p_6o_g.js +1 -0
- neutralino/_data/renderer/assets/dnd-DkNumIKC.js +5 -0
- neutralino/_data/renderer/assets/dropzone-aPCBPjDN.css +1 -0
- neutralino/_data/renderer/assets/dropzone-agrigkXv.js +1 -0
- neutralino/_data/renderer/assets/embla-carousel-react.esm-_ztrE73N.js +1 -0
- neutralino/_data/renderer/assets/emoji-Cj3VQHg8.js +1 -0
- neutralino/_data/renderer/assets/emoji-DV8OzU1E.css +1 -0
- neutralino/_data/renderer/assets/esm-DbOmMyz5.js +82 -0
- neutralino/_data/renderer/assets/highlight-Dlb5DJwL.css +1 -0
- neutralino/_data/renderer/assets/highlight-LH6Cyuz6.js +3 -0
- neutralino/_data/renderer/assets/html-CpATC083.js +1 -0
- neutralino/_data/renderer/assets/icon-chunk-C-4QDF6w.js +1 -0
- neutralino/_data/renderer/assets/index-CqHW60Dy.js +69 -0
- neutralino/_data/renderer/assets/index-TWpF4Lef.css +1 -0
- neutralino/_data/renderer/assets/javascript-D2QSKlDI.js +1 -0
- neutralino/_data/renderer/assets/json-D8zfYii3.js +1 -0
- neutralino/_data/renderer/assets/lightbox-BijRfmPy.js +1 -0
- neutralino/_data/renderer/assets/lightbox-BzKDpkAD.css +1 -0
- neutralino/_data/renderer/assets/markdown-Cpthnhzg.js +77 -0
- neutralino/_data/renderer/assets/markdown-CsS2tf5C.js +5 -0
- neutralino/_data/renderer/assets/python-B477ud9A.js +9 -0
- neutralino/_data/renderer/assets/richtext-BwtgvH7-.js +137 -0
- neutralino/_data/renderer/assets/richtext-DIAsHMuK.css +1 -0
- neutralino/_data/renderer/assets/spotlight-Ccstaz1-.css +1 -0
- neutralino/_data/renderer/assets/spotlight-Db1pwUWd.js +1 -0
- neutralino/_data/renderer/assets/sql-DbpHRl6F.js +2 -0
- neutralino/_data/renderer/assets/with-selector-CUfuSYau.js +1 -0
- neutralino/_data/renderer/assets/yaml-BPsr1O3S.js +1 -0
- neutralino/_data/renderer/index.html +22 -0
- neutralino/_data/renderer/manifest.json +202 -0
- neutralino/_data/renderer/neutralino.js +1 -0
- neutralino/_data/renderer/shared/mantine-core.mjs +5 -0
- neutralino/_data/renderer/shared/mantine-hooks.mjs +5 -0
- neutralino/_data/renderer/shared/react-dom-client.mjs +5 -0
- neutralino/_data/renderer/shared/react-dom.mjs +6 -0
- neutralino/_data/renderer/shared/react-jsx-runtime.mjs +5 -0
- neutralino/_data/renderer/shared/react.mjs +6 -0
- neutralino/_data/skills/README.md +6 -0
- neutralino/_data/skills/neutralino-app-patterns/SKILL.md +101 -0
- neutralino/_data/skills/neutralino-app-patterns/references/dashboards-and-background-work.md +55 -0
- neutralino/_data/skills/neutralino-app-patterns/references/storage-and-settings.md +57 -0
- neutralino/_data/skills/neutralino-app-patterns/references/tables-and-crud.md +81 -0
- neutralino/_data/skills/neutralino-frontend/SKILL.md +121 -0
- neutralino/_data/skills/neutralino-frontend/references/bridge.md +63 -0
- neutralino/_data/skills/neutralino-frontend/references/custom-components.md +84 -0
- neutralino/_data/skills/neutralino-frontend/references/frameworks.md +61 -0
- neutralino/_data/skills/neutralino-maintenance/SKILL.md +85 -0
- neutralino/_data/skills/neutralino-maintenance/references/platforms-and-gates.md +35 -0
- neutralino/_data/skills/neutralino-maintenance/references/records.md +38 -0
- neutralino/_data/skills/neutralino-maintenance/references/review-process.md +36 -0
- neutralino/_data/skills/neutralino-native/SKILL.md +107 -0
- neutralino/_data/skills/neutralino-native/references/api-conventions.md +72 -0
- neutralino/_data/skills/neutralino-native/references/desktop-helpers.md +53 -0
- neutralino/_data/skills/neutralino-native/references/permissions-windows.md +53 -0
- neutralino/_data/skills/neutralino-packaging/SKILL.md +99 -0
- neutralino/_data/skills/neutralino-packaging/references/build-layout.md +51 -0
- neutralino/_data/skills/neutralino-packaging/references/managed-install.md +59 -0
- neutralino/_data/skills/neutralino-packaging/references/templates-and-config.md +63 -0
- neutralino/_data/skills/neutralino-python/SKILL.md +109 -0
- neutralino/_data/skills/neutralino-python/references/architecture.md +53 -0
- neutralino/_data/skills/neutralino-python/references/cli.md +60 -0
- neutralino/_data/skills/neutralino-python/references/platforms-security.md +44 -0
- neutralino/_data/skills/neutralino-rpc/SKILL.md +114 -0
- neutralino/_data/skills/neutralino-rpc/references/errors-and-limits.md +44 -0
- neutralino/_data/skills/neutralino-rpc/references/expose-and-context.md +74 -0
- neutralino/_data/skills/neutralino-rpc/references/streams-and-cancellation.md +53 -0
- neutralino/_data/skills/neutralino-ui/SKILL.md +115 -0
- neutralino/_data/skills/neutralino-ui/references/components-and-tree.md +74 -0
- neutralino/_data/skills/neutralino-ui/references/state-forms-events.md +85 -0
- neutralino/_data/skills/neutralino-ui/references/themes-profiles-assets.md +105 -0
- neutralino/_data/skills/neutralino-updates/SKILL.md +94 -0
- neutralino/_data/skills/neutralino-updates/references/config-and-api.md +80 -0
- neutralino/_data/skills/neutralino-updates/references/releases-and-install.md +77 -0
- neutralino/_data/skills/neutralino-updates/references/security-rollback.md +48 -0
- neutralino/_data/ui/contracts.json +32927 -0
- neutralino/_data/ui/emoji.json +1 -0
- neutralino/_data/upstream-lock.json +97 -0
- neutralino/_managed.py +1099 -0
- neutralino/_paths.py +220 -0
- neutralino/_platform.py +150 -0
- neutralino/_scaffold.py +344 -0
- neutralino/api/_base.py +99 -0
- neutralino/api/_custom.py +1350 -0
- neutralino/api/_dec.py +21 -0
- neutralino/api/_enc.py +80 -0
- neutralino/api/app.py +119 -0
- neutralino/api/clipboard.py +101 -0
- neutralino/api/computer.py +261 -0
- neutralino/api/custom.py +36 -0
- neutralino/api/debug.py +41 -0
- neutralino/api/extensions.py +57 -0
- neutralino/api/filesystem.py +633 -0
- neutralino/api/net.py +22 -0
- neutralino/api/os.py +508 -0
- neutralino/api/resources.py +124 -0
- neutralino/api/server.py +66 -0
- neutralino/api/storage.py +98 -0
- neutralino/api/types.py +342 -0
- neutralino/api/updater.py +22 -0
- neutralino/api/window.py +397 -0
- neutralino/application.py +1261 -0
- neutralino/bundle.py +187 -0
- neutralino/cli.py +629 -0
- neutralino/client.py +496 -0
- neutralino/config.py +671 -0
- neutralino/devtools.py +1973 -0
- neutralino/errors.py +142 -0
- neutralino/events.py +579 -0
- neutralino/execution.py +293 -0
- neutralino/extension.py +134 -0
- neutralino/frontend/python-bridge.d.ts +207 -0
- neutralino/frontend/python-bridge.mjs +854 -0
- neutralino/protocol.py +456 -0
- neutralino/py.typed +0 -0
- neutralino/rpc.py +1625 -0
- neutralino/runtime.py +591 -0
- neutralino/supervisor.py +866 -0
- neutralino/sync_client.py +376 -0
- neutralino/templates/default/app.py +32 -0
- neutralino/templates/default/frontend/app.js +28 -0
- neutralino/templates/default/frontend/index.html +26 -0
- neutralino/templates/default/frontend/neutralino.js +1 -0
- neutralino/templates/default/frontend/styles.css +8 -0
- neutralino/templates/default/gitignore.txt +3 -0
- neutralino/templates/default/neutralino.config.json +25 -0
- neutralino/templates/hybrid/README.md +17 -0
- neutralino/templates/hybrid/app.py +49 -0
- neutralino/templates/hybrid/components/counter.mjs +37 -0
- neutralino/templates/hybrid/styles.css +21 -0
- neutralino/templates/python-ui/README.md +15 -0
- neutralino/templates/python-ui/app.py +44 -0
- neutralino/templates/python-ui/gitignore.txt +3 -0
- neutralino/templates/python-ui/requirements.txt +4 -0
- neutralino/templates/react/README.md +28 -0
- neutralino/templates/react/app.py +52 -0
- neutralino/templates/react/components/widget.mjs +23 -0
- neutralino/templates/react/widget/package.json +20 -0
- neutralino/templates/react/widget/src/Widget.jsx +25 -0
- neutralino/templates/react/widget/vite.config.mjs +19 -0
- neutralino/transport.py +661 -0
- neutralino/types.py +93 -0
- neutralino/ui/__init__.py +139 -0
- neutralino/ui/_app.py +1529 -0
- neutralino/ui/_assets.py +407 -0
- neutralino/ui/_bases.py +1210 -0
- neutralino/ui/_behaviours.py +1066 -0
- neutralino/ui/_charts.py +732 -0
- neutralino/ui/_component.py +882 -0
- neutralino/ui/_dates.py +168 -0
- neutralino/ui/_desktop.py +879 -0
- neutralino/ui/_events.py +192 -0
- neutralino/ui/_filters.py +427 -0
- neutralino/ui/_forms.py +282 -0
- neutralino/ui/_protocol.py +201 -0
- neutralino/ui/_schedule.py +543 -0
- neutralino/ui/_security.py +106 -0
- neutralino/ui/_session.py +969 -0
- neutralino/ui/_state.py +199 -0
- neutralino/ui/_tables.py +256 -0
- neutralino/ui/_theme.py +154 -0
- neutralino/ui/blocks/__init__.py +19 -0
- neutralino/ui/blocks/_data.py +2239 -0
- neutralino/ui/blocks/_interactive.py +622 -0
- neutralino/ui/blocks/_layout.py +2967 -0
- neutralino/ui/components/__init__.py +81 -0
- neutralino/ui/components/_dates.py +879 -0
- neutralino/ui/components/_editors.py +217 -0
- neutralino/ui/components/_extensions.py +790 -0
- neutralino/ui/components/_extras.py +303 -0
- neutralino/ui/components/_generated.py +30565 -0
- neutralino/ui/components/_types.py +17 -0
- neutralino/ui/schema.py +824 -0
- neutralino/ui/validators.py +362 -0
- neutralino/updates/__init__.py +96 -0
- neutralino/updates/_http.py +320 -0
- neutralino/updates/_layout.py +762 -0
- neutralino/updates/archive.py +216 -0
- neutralino/updates/config.py +256 -0
- neutralino/updates/errors.py +97 -0
- neutralino/updates/install.sh.in +201 -0
- neutralino/updates/launcher.py +18 -0
- neutralino/updates/manager.py +808 -0
- neutralino/updates/manifest.py +196 -0
- neutralino/updates/release.py +314 -0
- neutralino/updates/semver.py +84 -0
- neutralino/updates/sources.py +392 -0
- neutralino/windows.py +316 -0
- neutralino_python-0.1.0rc1.dist-info/METADATA +117 -0
- neutralino_python-0.1.0rc1.dist-info/RECORD +521 -0
- neutralino_python-0.1.0rc1.dist-info/WHEEL +4 -0
- neutralino_python-0.1.0rc1.dist-info/entry_points.txt +3 -0
- neutralino_python-0.1.0rc1.dist-info/licenses/LICENSE +21 -0
- neutralino_python-0.1.0rc1.dist-info/licenses/THIRD_PARTY_NOTICES.md +16 -0
- neutralino_python-0.1.0rc1.dist-info/licenses/src/neutralino/_data/renderer/LICENSES/packages.json +1838 -0
neutralino/supervisor.py
ADDED
|
@@ -0,0 +1,866 @@
|
|
|
1
|
+
"""Owned runtime process: private instance root, launch, readiness, shutdown.
|
|
2
|
+
|
|
3
|
+
Used by :class:`~neutralino.AsyncApplication` for the main window and by the
|
|
4
|
+
window manager for every managed window (one runtime process each).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import asyncio
|
|
10
|
+
import atexit
|
|
11
|
+
import collections
|
|
12
|
+
import concurrent.futures
|
|
13
|
+
import contextlib
|
|
14
|
+
import ctypes
|
|
15
|
+
import errno
|
|
16
|
+
import json
|
|
17
|
+
import logging
|
|
18
|
+
import os
|
|
19
|
+
import queue
|
|
20
|
+
import select
|
|
21
|
+
import shutil
|
|
22
|
+
import signal
|
|
23
|
+
import socket
|
|
24
|
+
import stat
|
|
25
|
+
import subprocess
|
|
26
|
+
import sys
|
|
27
|
+
import tempfile
|
|
28
|
+
import threading
|
|
29
|
+
import time
|
|
30
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
31
|
+
from pathlib import Path
|
|
32
|
+
from typing import Any
|
|
33
|
+
|
|
34
|
+
from . import protocol
|
|
35
|
+
from ._platform import is_windows, link_directory, make_private_dir, secure_directory
|
|
36
|
+
from .config import CONFIG_FILE
|
|
37
|
+
from .errors import StartupError, ValidationError
|
|
38
|
+
from .runtime import RuntimeInfo
|
|
39
|
+
from .types import Credentials, Limits
|
|
40
|
+
|
|
41
|
+
__all__ = [
|
|
42
|
+
"RuntimeProcess",
|
|
43
|
+
"install_signal_cleanup",
|
|
44
|
+
"restore_signal_handlers",
|
|
45
|
+
"sweep_stale_roots",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
log = logging.getLogger("neutralino.supervisor")
|
|
49
|
+
|
|
50
|
+
ROOT_PREFIX = "neutralino-py-"
|
|
51
|
+
OWNER_FILE = ".owner"
|
|
52
|
+
|
|
53
|
+
# Runtimes started by this process and still alive, and the private instance
|
|
54
|
+
# roots staged for them. At interpreter exit, or when SIGTERM/SIGHUP would end
|
|
55
|
+
# this process, every survivor is stopped through its own handle (SIGTERM,
|
|
56
|
+
# short wait, SIGKILL) and the roots (which may still hold an auth export) are
|
|
57
|
+
# removed. Only the process that started them does this: a forked child
|
|
58
|
+
# inherits these sets, the atexit hook and the signal handlers (see
|
|
59
|
+
# _after_fork_in_child), and must never stop its parent's runtimes.
|
|
60
|
+
_LIVE: set[subprocess.Popen[bytes]] = set()
|
|
61
|
+
_ROOTS: set[Path] = set()
|
|
62
|
+
_FATAL_SIGNALS = ("SIGTERM", "SIGHUP")
|
|
63
|
+
_signals_installed = False
|
|
64
|
+
_replaced: list[int] = [] # fatal signals whose (default) disposition we replaced
|
|
65
|
+
_relay: socket.socket | None = None # write end of the wakeup socket pair
|
|
66
|
+
_fatal_running = False
|
|
67
|
+
_owner_pid = os.getpid()
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _after_fork_in_child() -> None:
|
|
71
|
+
global _owner_pid, _signals_installed, _spawner, _relay
|
|
72
|
+
_LIVE.clear()
|
|
73
|
+
_ROOTS.clear()
|
|
74
|
+
_spawner = None # the spawner thread does not exist in the child
|
|
75
|
+
if _signals_installed:
|
|
76
|
+
for signum in _replaced:
|
|
77
|
+
if signal.getsignal(signum) is _on_fatal_signal:
|
|
78
|
+
with contextlib.suppress(ValueError, OSError):
|
|
79
|
+
signal.signal(signum, signal.SIG_DFL)
|
|
80
|
+
_replaced.clear()
|
|
81
|
+
_signals_installed = False
|
|
82
|
+
if _relay is not None:
|
|
83
|
+
# The wakeup socket is shared with the parent: a signal of the child
|
|
84
|
+
# must never reach the parent's relay (it would signal the parent).
|
|
85
|
+
_unset_wakeup_fd(_relay)
|
|
86
|
+
_relay.close()
|
|
87
|
+
_relay = None
|
|
88
|
+
_owner_pid = os.getpid()
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if hasattr(os, "register_at_fork"):
|
|
92
|
+
os.register_at_fork(after_in_child=_after_fork_in_child)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@atexit.register
|
|
96
|
+
def _stop_survivors() -> None:
|
|
97
|
+
if os.getpid() != _owner_pid:
|
|
98
|
+
return # inherited from a parent process: not ours to stop
|
|
99
|
+
procs = [p for p in list(_LIVE) if p.poll() is None]
|
|
100
|
+
for proc in procs:
|
|
101
|
+
with contextlib.suppress(OSError):
|
|
102
|
+
proc.terminate()
|
|
103
|
+
deadline = time.monotonic() + 3.0
|
|
104
|
+
for proc in procs:
|
|
105
|
+
try:
|
|
106
|
+
proc.wait(max(0.0, deadline - time.monotonic()))
|
|
107
|
+
except subprocess.TimeoutExpired:
|
|
108
|
+
with contextlib.suppress(OSError):
|
|
109
|
+
proc.kill()
|
|
110
|
+
with contextlib.suppress(subprocess.TimeoutExpired):
|
|
111
|
+
proc.wait(1.0)
|
|
112
|
+
_LIVE.clear()
|
|
113
|
+
for root in list(_ROOTS):
|
|
114
|
+
_remove_tree(root)
|
|
115
|
+
_ROOTS.clear()
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _on_fatal_signal(signum: int, frame: Any) -> None:
|
|
119
|
+
"""SIGTERM/SIGHUP with no handler of the application's own: stop owned
|
|
120
|
+
runtimes, then die from the same signal (atexit does not run on signals).
|
|
121
|
+
A nested call (the relay may deliver the signal a second time) returns."""
|
|
122
|
+
global _fatal_running
|
|
123
|
+
if _fatal_running:
|
|
124
|
+
return
|
|
125
|
+
_fatal_running = True
|
|
126
|
+
if os.getpid() == _owner_pid:
|
|
127
|
+
_stop_survivors()
|
|
128
|
+
signal.signal(signum, signal.SIG_DFL)
|
|
129
|
+
os.kill(os.getpid(), signum)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _relay_signals(sock: socket.socket) -> None:
|
|
133
|
+
"""Wake the main thread for a fatal signal another thread received.
|
|
134
|
+
|
|
135
|
+
Python runs signal handlers only in the main thread, and the kernel may
|
|
136
|
+
deliver a process-directed signal to any thread (spawner, pipe readers,
|
|
137
|
+
executor workers...). A main thread blocked in a system call (an event
|
|
138
|
+
loop's select, time.sleep) then never runs the handler. The C-level
|
|
139
|
+
handler writes the signal number to the wakeup fd from whatever thread it
|
|
140
|
+
ran on; this thread re-directs the signal at the main thread, whose
|
|
141
|
+
blocking call is interrupted so that the handler runs."""
|
|
142
|
+
main = threading.main_thread().ident
|
|
143
|
+
try:
|
|
144
|
+
while data := sock.recv(512):
|
|
145
|
+
for signum in set(data):
|
|
146
|
+
if (
|
|
147
|
+
main is not None
|
|
148
|
+
and signum in _replaced
|
|
149
|
+
and signal.getsignal(signum) is _on_fatal_signal
|
|
150
|
+
):
|
|
151
|
+
with contextlib.suppress(OSError, ValueError):
|
|
152
|
+
signal.pthread_kill(main, signum)
|
|
153
|
+
except OSError:
|
|
154
|
+
pass
|
|
155
|
+
finally:
|
|
156
|
+
sock.close()
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _start_relay() -> None:
|
|
160
|
+
global _relay
|
|
161
|
+
if _relay is not None or not hasattr(signal, "pthread_kill"):
|
|
162
|
+
return
|
|
163
|
+
r, w = socket.socketpair()
|
|
164
|
+
w.setblocking(False)
|
|
165
|
+
try:
|
|
166
|
+
previous = signal.set_wakeup_fd(w.fileno(), warn_on_full_buffer=False)
|
|
167
|
+
except (ValueError, OSError):
|
|
168
|
+
r.close()
|
|
169
|
+
w.close()
|
|
170
|
+
return
|
|
171
|
+
if previous != -1:
|
|
172
|
+
# Someone (an asyncio loop with signal handlers on this thread) already
|
|
173
|
+
# wakes the main thread: leave their wakeup fd alone.
|
|
174
|
+
signal.set_wakeup_fd(previous)
|
|
175
|
+
r.close()
|
|
176
|
+
w.close()
|
|
177
|
+
return
|
|
178
|
+
_relay = w
|
|
179
|
+
threading.Thread(
|
|
180
|
+
target=_relay_signals, args=(r,), name="neutralino-signal-relay", daemon=True
|
|
181
|
+
).start()
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _unset_wakeup_fd(w: socket.socket) -> None:
|
|
185
|
+
with contextlib.suppress(ValueError, OSError):
|
|
186
|
+
current = signal.set_wakeup_fd(-1)
|
|
187
|
+
if current != w.fileno():
|
|
188
|
+
signal.set_wakeup_fd(current) # replaced by someone else since: keep theirs
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def install_signal_cleanup() -> None:
|
|
192
|
+
"""Stop owned runtimes when this process is ended by SIGTERM or SIGHUP.
|
|
193
|
+
|
|
194
|
+
POSIX only and only from the main thread; installs a handler only for a
|
|
195
|
+
signal still at its default action, so an application's own handler is
|
|
196
|
+
never replaced (it then owns shutdown). Installed once: further calls do
|
|
197
|
+
nothing until :func:`restore_signal_handlers` has undone it.
|
|
198
|
+
"""
|
|
199
|
+
global _signals_installed
|
|
200
|
+
if _signals_installed or is_windows():
|
|
201
|
+
return
|
|
202
|
+
if threading.current_thread() is not threading.main_thread():
|
|
203
|
+
return
|
|
204
|
+
_signals_installed = True
|
|
205
|
+
for name in _FATAL_SIGNALS:
|
|
206
|
+
signum = getattr(signal, name, None)
|
|
207
|
+
if signum is not None and signal.getsignal(signum) is signal.SIG_DFL:
|
|
208
|
+
signal.signal(signum, _on_fatal_signal)
|
|
209
|
+
_replaced.append(signum)
|
|
210
|
+
if _replaced:
|
|
211
|
+
_start_relay()
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def restore_signal_handlers() -> bool:
|
|
215
|
+
"""Undo :func:`install_signal_cleanup` once this process owns no runtime.
|
|
216
|
+
|
|
217
|
+
Only from the main thread, and only while no runtime or instance root is
|
|
218
|
+
owned (otherwise nothing changes). Every signal whose handler is still
|
|
219
|
+
ours gets its default action back (a handler the application installed
|
|
220
|
+
since is kept), and the wakeup fd is unset again. Returns True when the
|
|
221
|
+
handlers are not (or no longer) installed.
|
|
222
|
+
"""
|
|
223
|
+
global _signals_installed, _relay
|
|
224
|
+
if not _signals_installed:
|
|
225
|
+
return True
|
|
226
|
+
if threading.current_thread() is not threading.main_thread() or _LIVE or _ROOTS:
|
|
227
|
+
return False
|
|
228
|
+
for signum in _replaced:
|
|
229
|
+
if signal.getsignal(signum) is _on_fatal_signal:
|
|
230
|
+
signal.signal(signum, signal.SIG_DFL)
|
|
231
|
+
_replaced.clear()
|
|
232
|
+
if _relay is not None:
|
|
233
|
+
w, _relay = _relay, None
|
|
234
|
+
_unset_wakeup_fd(w)
|
|
235
|
+
w.close() # the relay thread sees EOF, closes its end and ends
|
|
236
|
+
_signals_installed = False
|
|
237
|
+
return True
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
class _Spawner:
|
|
241
|
+
"""Starts runtimes from one thread that lives as long as this process.
|
|
242
|
+
|
|
243
|
+
On Linux every runtime gets ``PR_SET_PDEATHSIG(SIGKILL)``, so it dies with
|
|
244
|
+
this process even when the process is SIGKILLed (atexit and signal
|
|
245
|
+
handlers cannot run then). The kernel sends that signal when the *thread*
|
|
246
|
+
that forked the child exits, not the process, so the fork must never
|
|
247
|
+
happen on a short-lived thread such as an executor worker: it happens
|
|
248
|
+
here. Daemon: at interpreter exit the atexit hook has already stopped the
|
|
249
|
+
runtimes gracefully.
|
|
250
|
+
"""
|
|
251
|
+
|
|
252
|
+
def __init__(self) -> None:
|
|
253
|
+
self._jobs: queue.SimpleQueue[
|
|
254
|
+
tuple[concurrent.futures.Future[Any], Callable[..., Any], tuple[Any, ...]]
|
|
255
|
+
] = queue.SimpleQueue()
|
|
256
|
+
self._thread = threading.Thread(target=self._run, name="neutralino-spawner", daemon=True)
|
|
257
|
+
self._thread.start()
|
|
258
|
+
|
|
259
|
+
def submit(self, fn: Callable[..., Any], *args: Any) -> concurrent.futures.Future[Any]:
|
|
260
|
+
fut: concurrent.futures.Future[Any] = concurrent.futures.Future()
|
|
261
|
+
self._jobs.put((fut, fn, args))
|
|
262
|
+
return fut
|
|
263
|
+
|
|
264
|
+
def _run(self) -> None:
|
|
265
|
+
while True:
|
|
266
|
+
fut, fn, args = self._jobs.get()
|
|
267
|
+
if not fut.set_running_or_notify_cancel():
|
|
268
|
+
continue
|
|
269
|
+
try:
|
|
270
|
+
fut.set_result(fn(*args))
|
|
271
|
+
except BaseException as e: # delivered to the waiting coroutine
|
|
272
|
+
fut.set_exception(e)
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
_spawner: _Spawner | None = None
|
|
276
|
+
_spawner_lock = threading.Lock()
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def _get_spawner() -> _Spawner:
|
|
280
|
+
global _spawner
|
|
281
|
+
with _spawner_lock:
|
|
282
|
+
if _spawner is None:
|
|
283
|
+
_spawner = _Spawner()
|
|
284
|
+
return _spawner
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
_PR_SET_PDEATHSIG = 1
|
|
288
|
+
_TRAMPOLINE_EXIT = 125
|
|
289
|
+
_prctl: Any = None
|
|
290
|
+
|
|
291
|
+
# Runs in the child *after* exec, in a fresh single-threaded interpreter (no
|
|
292
|
+
# Python between fork and exec, unlike preexec_fn): sets PR_SET_PDEATHSIG,
|
|
293
|
+
# makes sure the owner has not died already, then execs the runtime (same pid;
|
|
294
|
+
# the death signal survives exec for a non-setuid binary).
|
|
295
|
+
_TRAMPOLINE = (
|
|
296
|
+
"import ctypes,os,sys\n"
|
|
297
|
+
"f=ctypes.CDLL(None,use_errno=True).prctl\n"
|
|
298
|
+
"f.argtypes=[ctypes.c_int]+[ctypes.c_ulong]*4\n"
|
|
299
|
+
"f.restype=ctypes.c_int\n"
|
|
300
|
+
f"if f({_PR_SET_PDEATHSIG},9,0,0,0)!=0 or os.getppid()!=int(sys.argv[1]):"
|
|
301
|
+
f"os._exit({_TRAMPOLINE_EXIT})\n"
|
|
302
|
+
"try:os.execv(sys.argv[2],sys.argv[2:])\n"
|
|
303
|
+
"except OSError as e:\n"
|
|
304
|
+
" sys.stderr.write('cannot execute the runtime: %s\\n'%e.strerror);os._exit(127)\n"
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def _trampoline_prefix(parent_pid: int) -> list[str]:
|
|
309
|
+
"""Command prefix that execs the runtime with PR_SET_PDEATHSIG(SIGKILL).
|
|
310
|
+
|
|
311
|
+
Linux only, and only with a real interpreter (a frozen application's
|
|
312
|
+
``sys.executable`` is the application itself): [] otherwise.
|
|
313
|
+
"""
|
|
314
|
+
if not sys.platform.startswith("linux") or getattr(sys, "frozen", False):
|
|
315
|
+
return []
|
|
316
|
+
if not sys.executable or not os.access(sys.executable, os.X_OK):
|
|
317
|
+
return []
|
|
318
|
+
return [sys.executable, "-I", "-S", "-c", _TRAMPOLINE, str(parent_pid)]
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def _death_signal_preexec() -> Callable[[], None] | None:
|
|
322
|
+
"""Fallback ``preexec_fn`` where the trampoline cannot run (a frozen
|
|
323
|
+
application on Linux): ties the child's life to this process.
|
|
324
|
+
|
|
325
|
+
Everything is resolved before the fork: the function only calls prctl,
|
|
326
|
+
getppid and _exit. CPython still runs at-fork hooks in the child before
|
|
327
|
+
it, which is why the trampoline is preferred. A failed prctl, or this
|
|
328
|
+
process dying between fork and prctl, makes the child exit at once.
|
|
329
|
+
"""
|
|
330
|
+
global _prctl
|
|
331
|
+
if not sys.platform.startswith("linux"):
|
|
332
|
+
return None
|
|
333
|
+
if _prctl is None:
|
|
334
|
+
try:
|
|
335
|
+
prctl = ctypes.CDLL(None, use_errno=True).prctl
|
|
336
|
+
except (OSError, AttributeError):
|
|
337
|
+
return None
|
|
338
|
+
prctl.argtypes = [ctypes.c_int, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong]
|
|
339
|
+
prctl.restype = ctypes.c_int
|
|
340
|
+
_prctl = prctl
|
|
341
|
+
prctl_fn = _prctl
|
|
342
|
+
parent = os.getpid()
|
|
343
|
+
sig = int(signal.SIGKILL)
|
|
344
|
+
getppid = os.getppid
|
|
345
|
+
exit_now = os._exit
|
|
346
|
+
|
|
347
|
+
def preexec() -> None:
|
|
348
|
+
if prctl_fn(_PR_SET_PDEATHSIG, sig, 0, 0) != 0 or getppid() != parent:
|
|
349
|
+
exit_now(_TRAMPOLINE_EXIT)
|
|
350
|
+
|
|
351
|
+
return preexec
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def _process_start_time(pid: int) -> str | None:
|
|
355
|
+
"""Kernel start time of ``pid`` (clock ticks since boot), or None."""
|
|
356
|
+
try:
|
|
357
|
+
stat_line = Path(f"/proc/{pid}/stat").read_text(encoding="utf-8")
|
|
358
|
+
except OSError:
|
|
359
|
+
return None
|
|
360
|
+
# comm (field 2) may contain spaces and parentheses: split after the last ")".
|
|
361
|
+
fields = stat_line.rsplit(")", 1)[-1].split()
|
|
362
|
+
return fields[19] if len(fields) > 19 else None
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def _write_owner(root: Path, pid: int | None = None) -> None:
|
|
366
|
+
"""Record which process staged ``root`` (pid + start time), so a later
|
|
367
|
+
process can prove the owner is gone before removing it."""
|
|
368
|
+
pid = os.getpid() if pid is None else pid
|
|
369
|
+
(root / OWNER_FILE).write_text(f"{pid} {_process_start_time(pid) or 0}\n", encoding="utf-8")
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
def sweep_stale_roots(parent: Path | None = None) -> list[Path]:
|
|
373
|
+
"""Remove instance roots left behind by SDK processes that no longer run
|
|
374
|
+
(e.g. SIGKILLed before they could clean up; the root may still hold an
|
|
375
|
+
auth export). Linux only. A directory is removed only if it has the SDK
|
|
376
|
+
prefix, is a real directory owned by this user, and holds an owner file
|
|
377
|
+
whose process (pid and start time) is gone. Returns the removed roots.
|
|
378
|
+
"""
|
|
379
|
+
if not Path("/proc/self/stat").exists():
|
|
380
|
+
return []
|
|
381
|
+
removed: list[Path] = []
|
|
382
|
+
base = parent or Path(tempfile.gettempdir())
|
|
383
|
+
try:
|
|
384
|
+
candidates = list(base.glob(ROOT_PREFIX + "*"))
|
|
385
|
+
except OSError:
|
|
386
|
+
return []
|
|
387
|
+
for root in candidates:
|
|
388
|
+
try:
|
|
389
|
+
st = root.lstat()
|
|
390
|
+
owner = root / OWNER_FILE
|
|
391
|
+
ost = owner.lstat()
|
|
392
|
+
if (
|
|
393
|
+
not stat.S_ISDIR(st.st_mode)
|
|
394
|
+
or st.st_uid != os.getuid()
|
|
395
|
+
or not stat.S_ISREG(ost.st_mode)
|
|
396
|
+
or ost.st_uid != os.getuid()
|
|
397
|
+
):
|
|
398
|
+
continue
|
|
399
|
+
pid_text, started = owner.read_text(encoding="utf-8").split()[:2]
|
|
400
|
+
pid = int(pid_text)
|
|
401
|
+
except (OSError, ValueError):
|
|
402
|
+
continue
|
|
403
|
+
if pid == os.getpid() or _process_start_time(pid) == started:
|
|
404
|
+
continue # owner still running
|
|
405
|
+
_remove_tree(root)
|
|
406
|
+
removed.append(root)
|
|
407
|
+
if removed:
|
|
408
|
+
log.info("removed %d stale instance root(s) of SDK processes that ended", len(removed))
|
|
409
|
+
return removed
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
_swept = False
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
runtime_log = logging.getLogger("neutralino.runtime")
|
|
416
|
+
|
|
417
|
+
RESOURCES_MOUNT = "/app/"
|
|
418
|
+
LOG_LINES = 200
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
class RuntimeProcess:
|
|
422
|
+
"""One runtime process owned by this Python process."""
|
|
423
|
+
|
|
424
|
+
def __init__(
|
|
425
|
+
self,
|
|
426
|
+
runtime: RuntimeInfo,
|
|
427
|
+
config: Mapping[str, Any],
|
|
428
|
+
*,
|
|
429
|
+
extension_id: str,
|
|
430
|
+
resources: Path | None,
|
|
431
|
+
cwd: Path | None = None,
|
|
432
|
+
env: Mapping[str, str] | None = None,
|
|
433
|
+
args: Sequence[str] = (),
|
|
434
|
+
limits: Limits | None = None,
|
|
435
|
+
name: str = "main",
|
|
436
|
+
) -> None:
|
|
437
|
+
self.runtime = runtime
|
|
438
|
+
self.config = dict(config)
|
|
439
|
+
self.extension_id = extension_id
|
|
440
|
+
self.resources = resources
|
|
441
|
+
self.cwd = cwd or Path.cwd()
|
|
442
|
+
self.env = dict(env) if env is not None else None
|
|
443
|
+
self.args = list(args)
|
|
444
|
+
self.limits = limits or Limits()
|
|
445
|
+
self.name = name
|
|
446
|
+
self.root: Path | None = None
|
|
447
|
+
self.proc: subprocess.Popen[bytes] | None = None
|
|
448
|
+
self.argv: list[str] = []
|
|
449
|
+
self.exit_code: int | None = None
|
|
450
|
+
self.exit_reason: str | None = None
|
|
451
|
+
self.stdout_tail: collections.deque[str] = collections.deque(maxlen=LOG_LINES)
|
|
452
|
+
self.stderr_tail: collections.deque[str] = collections.deque(maxlen=LOG_LINES)
|
|
453
|
+
self._readers: list[threading.Thread] = []
|
|
454
|
+
self._exit_pipe: tuple[int, int] | None = None # wakes the readers at exit (POSIX)
|
|
455
|
+
self._exited = asyncio.Event()
|
|
456
|
+
self._stopping = False
|
|
457
|
+
|
|
458
|
+
# ------------------------------------------------------------ staging
|
|
459
|
+
def _stage(self) -> Path:
|
|
460
|
+
global _swept
|
|
461
|
+
if not _swept and not is_windows():
|
|
462
|
+
_swept = True
|
|
463
|
+
with contextlib.suppress(OSError):
|
|
464
|
+
sweep_stale_roots()
|
|
465
|
+
root = make_private_dir(ROOT_PREFIX)
|
|
466
|
+
_ROOTS.add(root)
|
|
467
|
+
try:
|
|
468
|
+
if not is_windows():
|
|
469
|
+
_write_owner(root)
|
|
470
|
+
tmp = root / ".tmp"
|
|
471
|
+
tmp.mkdir(mode=0o700)
|
|
472
|
+
secure_directory(tmp)
|
|
473
|
+
if self.resources is not None:
|
|
474
|
+
if self.resources.is_dir():
|
|
475
|
+
link_directory(self.resources, root / RESOURCES_MOUNT.strip("/"))
|
|
476
|
+
else:
|
|
477
|
+
link_directory(self.resources, root / "resources.neu")
|
|
478
|
+
try:
|
|
479
|
+
text = json.dumps(self.config, indent=2, ensure_ascii=False)
|
|
480
|
+
except (TypeError, ValueError) as e:
|
|
481
|
+
raise ValidationError(f"the runtime config is not JSON-serialisable: {e}") from None
|
|
482
|
+
(root / CONFIG_FILE).write_text(text, encoding="utf-8")
|
|
483
|
+
except BaseException:
|
|
484
|
+
_ROOTS.discard(root)
|
|
485
|
+
_remove_tree(root)
|
|
486
|
+
raise
|
|
487
|
+
return root
|
|
488
|
+
|
|
489
|
+
@property
|
|
490
|
+
def auth_file(self) -> Path:
|
|
491
|
+
if self.root is None:
|
|
492
|
+
raise StartupError("the runtime's instance root is gone (stopped during startup)")
|
|
493
|
+
return self.root / ".tmp" / "auth_info.json"
|
|
494
|
+
|
|
495
|
+
def log_tail(self, lines: int = 40) -> str:
|
|
496
|
+
out = list(self.stdout_tail)[-lines:] + [
|
|
497
|
+
f"[stderr] {x}" for x in list(self.stderr_tail)[-lines:]
|
|
498
|
+
]
|
|
499
|
+
return "\n".join(out)
|
|
500
|
+
|
|
501
|
+
# ------------------------------------------------------------- launch
|
|
502
|
+
async def start(self) -> Credentials:
|
|
503
|
+
"""Launch and wait for the exported credentials (monotonic deadline)."""
|
|
504
|
+
loop = asyncio.get_running_loop()
|
|
505
|
+
deadline = loop.time() + self.limits.startup_timeout
|
|
506
|
+
install_signal_cleanup() # before anything is owned (see restore_signal_handlers)
|
|
507
|
+
self.root = self._stage()
|
|
508
|
+
bundle = self.resources is not None and not self.resources.is_dir()
|
|
509
|
+
self.argv = [
|
|
510
|
+
str(self.runtime.path),
|
|
511
|
+
f"--path={self.root}",
|
|
512
|
+
"--res-mode=bundle" if bundle else "--res-mode=directory",
|
|
513
|
+
*self.args,
|
|
514
|
+
]
|
|
515
|
+
kwargs: dict[str, Any] = {}
|
|
516
|
+
if is_windows():
|
|
517
|
+
kwargs["creationflags"] = 0x00000200 # CREATE_NEW_PROCESS_GROUP
|
|
518
|
+
else:
|
|
519
|
+
kwargs["start_new_session"] = True # terminal Ctrl-C reaches Python only
|
|
520
|
+
kwargs["umask"] = 0o077 # auth file and logs are created private
|
|
521
|
+
launched_at = time.time()
|
|
522
|
+
# Popen runs on the spawner thread (see _Spawner). The wait for it is
|
|
523
|
+
# part of the startup deadline and ends on cancellation; a spawn that
|
|
524
|
+
# completes after that is stopped (and its root removed) in the
|
|
525
|
+
# background by _abandon_spawn, so the handle is never lost.
|
|
526
|
+
job = _get_spawner().submit(_spawn, self.argv, str(self.cwd), self.env, kwargs)
|
|
527
|
+
try:
|
|
528
|
+
proc: subprocess.Popen[bytes] = await asyncio.wait_for(
|
|
529
|
+
asyncio.shield(asyncio.wrap_future(job)),
|
|
530
|
+
max(0.0, deadline - loop.time()),
|
|
531
|
+
)
|
|
532
|
+
except TimeoutError: # (an OSError subclass: before OSError)
|
|
533
|
+
self._abandon_spawn(job)
|
|
534
|
+
raise StartupError(
|
|
535
|
+
f"the runtime could not be started within {self.limits.startup_timeout:g}s "
|
|
536
|
+
"(process creation did not complete); it is stopped if it still starts",
|
|
537
|
+
) from None
|
|
538
|
+
except OSError as e:
|
|
539
|
+
await self._cleanup_root()
|
|
540
|
+
raise StartupError(f"cannot start the runtime {self.runtime.path}: {e}") from None
|
|
541
|
+
except BaseException: # cancelled: do not wait for the spawn
|
|
542
|
+
self._abandon_spawn(job)
|
|
543
|
+
raise
|
|
544
|
+
self.proc = proc
|
|
545
|
+
_LIVE.add(proc)
|
|
546
|
+
assert proc.stdout is not None and proc.stderr is not None
|
|
547
|
+
if not is_windows():
|
|
548
|
+
self._exit_pipe = os.pipe()
|
|
549
|
+
wake = self._exit_pipe[0] if self._exit_pipe is not None else None
|
|
550
|
+
# Reader threads, not asyncio pipes: processes the runtime starts (raw
|
|
551
|
+
# window.create, os.spawnProcess) inherit these pipes and may outlive it.
|
|
552
|
+
self._readers = [
|
|
553
|
+
threading.Thread(
|
|
554
|
+
target=_pump,
|
|
555
|
+
args=(proc.stdout, self.stdout_tail, logging.INFO, self.name, wake),
|
|
556
|
+
daemon=True,
|
|
557
|
+
name=f"neutralino-log-{self.name}",
|
|
558
|
+
),
|
|
559
|
+
threading.Thread(
|
|
560
|
+
target=_pump,
|
|
561
|
+
args=(proc.stderr, self.stderr_tail, logging.WARNING, self.name, wake),
|
|
562
|
+
daemon=True,
|
|
563
|
+
name=f"neutralino-err-{self.name}",
|
|
564
|
+
),
|
|
565
|
+
]
|
|
566
|
+
for t in self._readers:
|
|
567
|
+
t.start()
|
|
568
|
+
self._watch_exit(loop)
|
|
569
|
+
try:
|
|
570
|
+
while True:
|
|
571
|
+
if self._stopping:
|
|
572
|
+
raise StartupError("the runtime was stopped during startup")
|
|
573
|
+
if self._exited.is_set():
|
|
574
|
+
raise StartupError(
|
|
575
|
+
f"runtime exited during startup with code {self.exit_code}",
|
|
576
|
+
exit_code=self.exit_code,
|
|
577
|
+
log_tail=self.log_tail(),
|
|
578
|
+
)
|
|
579
|
+
creds = self._read_auth(launched_at)
|
|
580
|
+
if creds is not None:
|
|
581
|
+
return creds
|
|
582
|
+
if loop.time() > deadline:
|
|
583
|
+
raise StartupError(
|
|
584
|
+
f"runtime did not export credentials within "
|
|
585
|
+
f"{self.limits.startup_timeout:g}s",
|
|
586
|
+
log_tail=self.log_tail(),
|
|
587
|
+
)
|
|
588
|
+
await asyncio.sleep(0.02)
|
|
589
|
+
except BaseException:
|
|
590
|
+
await self.stop()
|
|
591
|
+
raise
|
|
592
|
+
|
|
593
|
+
def _abandon_spawn(self, job: concurrent.futures.Future[Any]) -> None:
|
|
594
|
+
"""Startup gave up while the spawner had not finished this launch.
|
|
595
|
+
|
|
596
|
+
A launch still queued is cancelled (nothing is started). Otherwise the
|
|
597
|
+
process, once Popen returns, is stopped through its own handle on a
|
|
598
|
+
background thread and only then is its root removed. Ownership of the
|
|
599
|
+
root moves there: start() does not wait for any of this.
|
|
600
|
+
"""
|
|
601
|
+
root, self.root = self.root, None
|
|
602
|
+
if job.cancel():
|
|
603
|
+
if root is not None:
|
|
604
|
+
_remove_tree(root)
|
|
605
|
+
_ROOTS.discard(root)
|
|
606
|
+
return
|
|
607
|
+
grace = self.limits.shutdown_grace
|
|
608
|
+
name = self.name
|
|
609
|
+
|
|
610
|
+
def reap() -> None:
|
|
611
|
+
proc: subprocess.Popen[bytes] | None = None
|
|
612
|
+
with contextlib.suppress(BaseException):
|
|
613
|
+
proc = job.result()
|
|
614
|
+
if proc is not None:
|
|
615
|
+
log.info("stopping runtime %s that started after its startup was abandoned", name)
|
|
616
|
+
_terminate(proc, grace)
|
|
617
|
+
for stream in (proc.stdout, proc.stderr):
|
|
618
|
+
if stream is not None:
|
|
619
|
+
with contextlib.suppress(OSError):
|
|
620
|
+
stream.close()
|
|
621
|
+
_LIVE.discard(proc)
|
|
622
|
+
if root is not None:
|
|
623
|
+
_remove_tree(root)
|
|
624
|
+
_ROOTS.discard(root)
|
|
625
|
+
|
|
626
|
+
job.add_done_callback(
|
|
627
|
+
lambda _: threading.Thread(
|
|
628
|
+
target=reap, name=f"neutralino-reap-{name}", daemon=True
|
|
629
|
+
).start()
|
|
630
|
+
)
|
|
631
|
+
|
|
632
|
+
def _read_auth(self, launched_at: float) -> Credentials | None:
|
|
633
|
+
path = self.auth_file
|
|
634
|
+
try:
|
|
635
|
+
st = path.lstat()
|
|
636
|
+
except FileNotFoundError:
|
|
637
|
+
return None
|
|
638
|
+
if not stat.S_ISREG(st.st_mode):
|
|
639
|
+
raise StartupError("auth export is not a regular file (symlink?)")
|
|
640
|
+
if not is_windows() and st.st_uid != os.getuid():
|
|
641
|
+
raise StartupError("auth export is owned by another user")
|
|
642
|
+
if st.st_mtime < launched_at - 2:
|
|
643
|
+
return None # stale file: not from this launch
|
|
644
|
+
try:
|
|
645
|
+
raw = path.read_bytes()
|
|
646
|
+
return protocol.parse_auth_file(raw, self.extension_id)
|
|
647
|
+
except (OSError, ValueError):
|
|
648
|
+
return None # partially written; poll again
|
|
649
|
+
|
|
650
|
+
def remove_auth_file(self) -> None:
|
|
651
|
+
"""Delete the exported credentials once connected (ADR-003)."""
|
|
652
|
+
with contextlib.suppress(OSError):
|
|
653
|
+
self.auth_file.unlink()
|
|
654
|
+
|
|
655
|
+
def _watch_exit(self, loop: asyncio.AbstractEventLoop) -> None:
|
|
656
|
+
"""waitpid on our own child only, on a daemon thread: it returns when
|
|
657
|
+
the runtime exits even if grandchildren still hold its output pipes,
|
|
658
|
+
and (unlike an executor worker) never makes interpreter exit wait for
|
|
659
|
+
the runtime, so the atexit cleanup can run."""
|
|
660
|
+
proc = self.proc
|
|
661
|
+
assert proc is not None
|
|
662
|
+
|
|
663
|
+
exit_pipe = self._exit_pipe
|
|
664
|
+
|
|
665
|
+
def wait() -> None:
|
|
666
|
+
code = proc.wait()
|
|
667
|
+
_LIVE.discard(proc)
|
|
668
|
+
if exit_pipe is not None:
|
|
669
|
+
with contextlib.suppress(OSError):
|
|
670
|
+
os.write(exit_pipe[1], b"x") # readers drain, then end
|
|
671
|
+
with contextlib.suppress(RuntimeError): # the loop is already closed
|
|
672
|
+
loop.call_soon_threadsafe(self._on_exit, code)
|
|
673
|
+
|
|
674
|
+
threading.Thread(target=wait, name=f"neutralino-wait-{self.name}", daemon=True).start()
|
|
675
|
+
|
|
676
|
+
def _on_exit(self, code: int) -> None:
|
|
677
|
+
self.exit_code = code
|
|
678
|
+
if self.exit_reason is None:
|
|
679
|
+
self.exit_reason = "stopped by SDK" if self._stopping else "runtime exited"
|
|
680
|
+
self._exited.set()
|
|
681
|
+
|
|
682
|
+
@property
|
|
683
|
+
def running(self) -> bool:
|
|
684
|
+
return self.proc is not None and not self._exited.is_set()
|
|
685
|
+
|
|
686
|
+
async def wait_exit(self) -> int | None:
|
|
687
|
+
await self._exited.wait()
|
|
688
|
+
return self.exit_code
|
|
689
|
+
|
|
690
|
+
@property
|
|
691
|
+
def pid(self) -> int | None:
|
|
692
|
+
return self.proc.pid if self.proc is not None else None
|
|
693
|
+
|
|
694
|
+
# --------------------------------------------------------------- stop
|
|
695
|
+
async def stop(self, *, graceful: Any = None) -> int | None:
|
|
696
|
+
"""Stop the owned runtime: graceful -> bounded wait -> terminate -> kill.
|
|
697
|
+
|
|
698
|
+
POSIX graceful = SIGTERM (upstream's own handler); Windows graceful =
|
|
699
|
+
the ``graceful`` coroutine (app.exit) when given. Only the process handle
|
|
700
|
+
held here is signalled. Idempotent.
|
|
701
|
+
"""
|
|
702
|
+
self._stopping = True
|
|
703
|
+
proc = self.proc
|
|
704
|
+
if proc is not None and not self._exited.is_set():
|
|
705
|
+
grace = self.limits.shutdown_grace
|
|
706
|
+
if is_windows() and graceful is not None:
|
|
707
|
+
# Windows: app.exit over the socket; TerminateProcess afterwards.
|
|
708
|
+
with contextlib.suppress(Exception):
|
|
709
|
+
await asyncio.wait_for(graceful, grace)
|
|
710
|
+
else:
|
|
711
|
+
if asyncio.iscoroutine(graceful):
|
|
712
|
+
graceful.close()
|
|
713
|
+
# POSIX: upstream's SIGTERM handler is the graceful path (ADR-005).
|
|
714
|
+
with contextlib.suppress(ProcessLookupError):
|
|
715
|
+
proc.send_signal(signal.SIGTERM)
|
|
716
|
+
try:
|
|
717
|
+
await asyncio.wait_for(self._exited.wait(), grace)
|
|
718
|
+
except TimeoutError:
|
|
719
|
+
log.warning("runtime %s ignored the graceful stop; killing it", self.name)
|
|
720
|
+
with contextlib.suppress(ProcessLookupError):
|
|
721
|
+
proc.kill() # SIGKILL / TerminateProcess, through our own handle
|
|
722
|
+
await self._exited.wait()
|
|
723
|
+
elif graceful is not None and asyncio.iscoroutine(graceful):
|
|
724
|
+
graceful.close()
|
|
725
|
+
for t in self._readers:
|
|
726
|
+
# Bounded; on POSIX the readers end once the runtime has exited even
|
|
727
|
+
# when a process it started still holds the pipes.
|
|
728
|
+
await asyncio.to_thread(t.join, 2.0)
|
|
729
|
+
if self._exit_pipe is not None and not any(t.is_alive() for t in self._readers):
|
|
730
|
+
for fd in self._exit_pipe:
|
|
731
|
+
with contextlib.suppress(OSError):
|
|
732
|
+
os.close(fd)
|
|
733
|
+
self._exit_pipe = None
|
|
734
|
+
await self._cleanup_root()
|
|
735
|
+
return self.exit_code
|
|
736
|
+
|
|
737
|
+
async def _cleanup_root(self) -> None:
|
|
738
|
+
root = self.root
|
|
739
|
+
if root is None:
|
|
740
|
+
return
|
|
741
|
+
self.root = None
|
|
742
|
+
await asyncio.to_thread(_remove_tree, root)
|
|
743
|
+
_ROOTS.discard(root)
|
|
744
|
+
restore_signal_handlers() # only from the main thread, once nothing is owned
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
def _remove_tree(root: Path) -> None:
|
|
748
|
+
"""Remove our instance root without following the resource link."""
|
|
749
|
+
for name in ("app", "resources.neu"):
|
|
750
|
+
link = root / name
|
|
751
|
+
with contextlib.suppress(OSError):
|
|
752
|
+
if link.is_symlink():
|
|
753
|
+
link.unlink()
|
|
754
|
+
elif sys.platform == "win32" and getattr(link, "is_junction", lambda: False)():
|
|
755
|
+
link.rmdir()
|
|
756
|
+
shutil.rmtree(root, ignore_errors=True)
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
def _terminate(proc: subprocess.Popen[bytes], grace: float) -> None:
|
|
760
|
+
"""Blocking terminate -> bounded wait -> kill of our own child."""
|
|
761
|
+
with contextlib.suppress(OSError):
|
|
762
|
+
proc.terminate()
|
|
763
|
+
try:
|
|
764
|
+
proc.wait(grace)
|
|
765
|
+
except subprocess.TimeoutExpired:
|
|
766
|
+
with contextlib.suppress(OSError):
|
|
767
|
+
proc.kill()
|
|
768
|
+
with contextlib.suppress(subprocess.TimeoutExpired):
|
|
769
|
+
proc.wait(5.0)
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
_DRAIN_SECONDS = 1.0 # after the runtime exited: read what is buffered, then stop
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
def _pump(
|
|
776
|
+
stream: Any, tail: collections.deque[str], level: int, name: str, wake: int | None = None
|
|
777
|
+
) -> None:
|
|
778
|
+
"""Read one runtime output pipe line by line into a bounded tail.
|
|
779
|
+
|
|
780
|
+
Processes the runtime starts (raw window.create, os.spawnProcess) inherit
|
|
781
|
+
the pipe and may outlive it, so EOF may never come. With ``wake`` (POSIX:
|
|
782
|
+
the read end of a pipe written when the runtime exits) the reader drains
|
|
783
|
+
what is already buffered and then ends.
|
|
784
|
+
"""
|
|
785
|
+
|
|
786
|
+
def emit(raw: bytes) -> None:
|
|
787
|
+
text = raw[:4000].decode("utf-8", "replace").rstrip("\r\n")
|
|
788
|
+
tail.append(text)
|
|
789
|
+
if runtime_log.isEnabledFor(level):
|
|
790
|
+
runtime_log.log(level, "[%s] %s", name, text)
|
|
791
|
+
|
|
792
|
+
try:
|
|
793
|
+
if wake is None:
|
|
794
|
+
for raw in iter(stream.readline, b""):
|
|
795
|
+
emit(raw)
|
|
796
|
+
return
|
|
797
|
+
fd = stream.fileno()
|
|
798
|
+
buf = b""
|
|
799
|
+
drain_until: float | None = None
|
|
800
|
+
while True:
|
|
801
|
+
timeout = None if drain_until is None else max(0.0, drain_until - time.monotonic())
|
|
802
|
+
ready, _, _ = select.select(
|
|
803
|
+
[fd] if drain_until is not None else [fd, wake], [], [], timeout
|
|
804
|
+
)
|
|
805
|
+
if fd not in ready:
|
|
806
|
+
if drain_until is not None:
|
|
807
|
+
break # runtime gone and nothing more arrived in time
|
|
808
|
+
drain_until = time.monotonic() + _DRAIN_SECONDS
|
|
809
|
+
continue
|
|
810
|
+
chunk = os.read(fd, 65536)
|
|
811
|
+
if not chunk:
|
|
812
|
+
break
|
|
813
|
+
buf += chunk
|
|
814
|
+
*lines, buf = buf.split(b"\n")
|
|
815
|
+
for line in lines:
|
|
816
|
+
emit(line)
|
|
817
|
+
if len(buf) > 65536:
|
|
818
|
+
emit(buf)
|
|
819
|
+
buf = b""
|
|
820
|
+
if buf:
|
|
821
|
+
emit(buf)
|
|
822
|
+
except (OSError, ValueError):
|
|
823
|
+
pass
|
|
824
|
+
finally:
|
|
825
|
+
with contextlib.suppress(OSError):
|
|
826
|
+
stream.close()
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
def _spawn(
|
|
830
|
+
argv: list[str], cwd: str, env: dict[str, str] | None, kwargs: dict[str, Any]
|
|
831
|
+
) -> subprocess.Popen[bytes]:
|
|
832
|
+
proc = _popen(argv, cwd, env, kwargs)
|
|
833
|
+
_LIVE.add(proc)
|
|
834
|
+
return proc
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
def _popen(
|
|
838
|
+
argv: list[str], cwd: str, env: dict[str, str] | None, kwargs: dict[str, Any]
|
|
839
|
+
) -> subprocess.Popen[bytes]:
|
|
840
|
+
if is_windows():
|
|
841
|
+
return subprocess.Popen(
|
|
842
|
+
argv,
|
|
843
|
+
cwd=cwd,
|
|
844
|
+
env=env,
|
|
845
|
+
stdin=subprocess.DEVNULL,
|
|
846
|
+
stdout=subprocess.PIPE,
|
|
847
|
+
stderr=subprocess.PIPE,
|
|
848
|
+
creationflags=int(kwargs.get("creationflags", 0)),
|
|
849
|
+
)
|
|
850
|
+
prefix = _trampoline_prefix(os.getpid())
|
|
851
|
+
if prefix and not os.access(argv[0], os.X_OK):
|
|
852
|
+
# The error a direct Popen raises (the trampoline could only report an
|
|
853
|
+
# exit code).
|
|
854
|
+
code = errno.EACCES if Path(argv[0]).exists() else errno.ENOENT
|
|
855
|
+
raise OSError(code, os.strerror(code), argv[0])
|
|
856
|
+
return subprocess.Popen(
|
|
857
|
+
prefix + argv,
|
|
858
|
+
cwd=cwd,
|
|
859
|
+
env=env,
|
|
860
|
+
stdin=subprocess.DEVNULL,
|
|
861
|
+
stdout=subprocess.PIPE,
|
|
862
|
+
stderr=subprocess.PIPE,
|
|
863
|
+
start_new_session=True,
|
|
864
|
+
umask=int(kwargs.get("umask", 0o077)),
|
|
865
|
+
preexec_fn=None if prefix else _death_signal_preexec(),
|
|
866
|
+
)
|