Skip to main content

A simple library for creating windows services and logging using windows event log

Project description

Cognite Windows Service Library

This is a python/rust library for running python programs as simple windows services. It supports basic event logging, though you will need to define the event message source yourself, typically through a windows installer or similar.

Unlike other windows service libraries, it does not have code to actually create the windows service, again assuming that this is done externally.

Event logging uses the user provided event log source name, and logs plain text to event ID 0.

Usage

See the python interface. Simply install the library, call register_service, and once the extractor has come somewhat online, call set_service_running on the ServiceHandle passed to the startup callback. See method docs.

from simple_winservice import register_service, run_service, ServiceHandle
from threading import Event

token = Event()

def cancel_service() -> None:
    token.set()

def service_main(handle: ServiceHandle, args: list[str]) -> None:
    handle.event_log_info("Service is now running!")

    while not token.wait(1):
        handle.event_log_info("Service is still running!")

    handle.event_log_info("Service is shutting down now")

def main() -> None:
    register_service(service_main, "MyTestService", cancel_service)
    run_service()

if __name__ == "__main__":
    main()

Development

You will need maturin, and rust/cargo, installed using rustup. To build, activate a local venv, then just run maturin develop, after which the local venv will contain an installed version of the library you can use. There's a sample service in the service_test.py file, which is intended to be run as a windows service called with entry point .../.env/Scripts/python.exe .../service_test.py more arguments here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_winservice-0.1.1.tar.gz (15.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

simple_winservice-0.1.1-cp313-cp313-win_amd64.whl (145.0 kB view details)

Uploaded CPython 3.13Windows x86-64

simple_winservice-0.1.1-cp312-cp312-win_amd64.whl (145.2 kB view details)

Uploaded CPython 3.12Windows x86-64

simple_winservice-0.1.1-cp311-cp311-win_amd64.whl (144.8 kB view details)

Uploaded CPython 3.11Windows x86-64

simple_winservice-0.1.1-cp310-cp310-win_amd64.whl (144.8 kB view details)

Uploaded CPython 3.10Windows x86-64

File details

Details for the file simple_winservice-0.1.1.tar.gz.

File metadata

  • Download URL: simple_winservice-0.1.1.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for simple_winservice-0.1.1.tar.gz
Algorithm Hash digest
SHA256 385a01fe2168195dccf141f47f1184f0df87076c133422ca823e4d4b8af3bf6b
MD5 aedaa05c65bf3964537bc2efbe838ac5
BLAKE2b-256 f00c17e5ac389abdf319136eb2fc6180f7f422c4377063ca55a2c4e203b342c4

See more details on using hashes here.

File details

Details for the file simple_winservice-0.1.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for simple_winservice-0.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a252e94eae1a029e9d285f33efb1e66d5c9d74776336e15c7d244820a5eee815
MD5 a8cd2a80b319b5006f4a831cb03fb4f7
BLAKE2b-256 c2e39fbfb4495f53f79350c66d845ee381beb1d1f2dccbf2a9c58b1336d489b7

See more details on using hashes here.

File details

Details for the file simple_winservice-0.1.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for simple_winservice-0.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 248959b741023fce355af34b5de59cb36ae22ffdd581a1b6a7e37b4ca1ea20c1
MD5 b4c96731cb95ad480da53a7b9fd3120e
BLAKE2b-256 87eefce7264f0cab08e7199de50a2b5d690428823bb0692a876a2a45f9f9b404

See more details on using hashes here.

File details

Details for the file simple_winservice-0.1.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for simple_winservice-0.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 80710fcd48bc253473926929e910b4dce07e2181d4dee0dbd7525dd99f5a8cf2
MD5 4496c9c4220aa5131a840b8e4d4d0461
BLAKE2b-256 db3fbaa8679362ece7b735b9325e3730bb629281d3f3d6bae3cd18a990111099

See more details on using hashes here.

File details

Details for the file simple_winservice-0.1.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for simple_winservice-0.1.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b32477eb7f9135b5fcd2b21e8db8d6002ad573e8bcafddf795bf6c27f8b3bdcf
MD5 f036adb28a90416de1f7ec20e1696b74
BLAKE2b-256 8dbb7134e01b42633b5e4b1d82a1bd4c95730fe0151043a4b5d646868c9192d2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page