Metadata-Version: 2.1
Name: as-service
Version: 0.1.1
Summary: function as windows service wrapper with threading
Home-page: https://github.com/BeanLiu1994/as_service
Author: beanliu
Author-email: njueebeanliu@hotmail.com
License: MIT
Keywords: service windows svc
Platform: UNKNOWN
Classifier: Operating System :: Microsoft :: Windows
Classifier: Programming Language :: Python :: 3
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pywin32

# 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


