Skip to main content

WhatAmIThinking-Services

Cross-platform service library for building platform services that integrate with platform tooling and can be installed/started/stopped/uninstalled from the command line.

Table of Contents

Code Usage

You should subclass PlatformService and override the following methods:

  • run: put your core blocking logic for running your service here
    • call self.started() just before you start blocking in this method to signal to the platform that your service has started
    • call self.stopped() just before this returns to signal to the platform your service has stopped
  • stop: send signal to stop your service and wait for it to be stopped.
import time
import threading

from whatamithinking.services import PlatformService


class MyService(PlatformService):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._event = threading.Event()
        self._exited = threading.Event()

    def run(self):
        self.started()
        self._event.wait()
        self._exited.set()
        self.stopped()

    def stop(self):
        self._event.set()
        self._exited.wait()


if __name__ == '__main__':
    # this will handle commandline params and run your service
    MyService.execute()

CLI

A CLI is included in the service class execute method, so you can perform operations such as install, uninstall, etc. The following is an example showing the CLI.

Main

usage: My Service [-h] {install,uninstall,start,stop} ...

Description of my service

options:
  -h, --help            show this help message and exit

subcommand:
  {install,uninstall,start,stop}

Install Subcommand

usage: My Service install [-h] [--username USERNAME] [--password PASSWORD]

install the service on this machine

options:
  -h, --help           show this help message and exit
  --username USERNAME  domain\username of the account to run the service under
  --password PASSWORD  password of the account to run the service under

Uninstall Subcommand

usage: My Service uninstall [-h]

uninstall the service from the machine

options:
  -h, --help  show this help message and exit

Start Subcommand

usage: My Service start [-h]

start the service if it is installed or throw error if not

options:
  -h, --help  show this help message and exit

Stop Subcommand

usage: My Service stop [-h]

stop the service if it is installed or throw error if not

options:
  -h, --help  show this help message and exit

Platforms

Windows

NOTE: obscure bug was found when trying to run installer to update and event viewer was open at same time. servicemanager.pyd file becomes locked up. turns out event viewer does this. closing event viewer removes this lock. see: https://mail.python.org/pipermail/python-win32/2004-December/002736.html

Metadata

Release files for whatamithinking-services 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for whatamithinking-services 1.1.2
File Size Uploaded
whatamithinking_services-1.1.2.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for whatamithinking-services 1.1.2
File Interpreter ABI Platform
whatamithinking_services-1.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / whatamithinking_services-1.1.2.tar.gz

Download URL whatamithinking_services-1.1.2.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6b61f57718436a575f08676aa53c4fc523f3529c7942677fe29e26a9cacd3eea
BLAKE2b-256 checksum
How to use checksums
722a45587860fecdcf685dea8e10ff2a35ecb573fd029141a66322e536af1318
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / whatamithinking_services-1.1.2-py3-none-any.whl

Download URL whatamithinking_services-1.1.2-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ffcc20f03bf318e9623ebfac0a63a4b4467dfa3fa9ad2fbefbf0e77c532d7c9b
BLAKE2b-256 checksum
How to use checksums
6818950d916d8f1e9927fd363fb22d18a13f89550eacd3bab6f9e5cc35638430
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page