semvec/pypi-packages huggingface dataset:
as-service 0.1.1
function as windows service wrapper with threading
License: MIT
Keywords: service windows svc

# as_service

as_service is a Python package that provides a way to create Windows service.

## Installation

```bash
pip install as_service
```

## Usage

```python
from as_service import AppServerSvc

class MyService(AppServerSvc):
    _svc_name_ = "MyService"
    _svc_display_name_ = "My Service"
    _svc_description_ = 'Python Service Description'

    def client_main(self, event:threading.Event):
        while not event.is_set():
            try:
                with open(r"C:\test.txt", "w") as f:
                    f.write("hello")
                time.sleep(3)
            except:
                import traceback
                traceback.print_exc()

if __name__ == '__main__':
    # elevate
    # if access denied, you might have installed python from win store, it won't work with pythonservice
    if not ctypes.windll.shell32.IsUserAnAdmin():
        ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
        sys.exit(0)
    try:
        MyService.logger().addHandler(logging.StreamHandler())
        MyService.logger().addHandler(logging.FileHandler("log.txt"))
        MyService.cli()
    except Exception as e:
        MyService.logger().exception(e)
    finally:
        time.sleep(2)
```

## License

MIT License