as_service
as_service is a Python package that provides a way to create Windows service.
Installation
pip install as_service
Usage
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
Metadata
Release files for as-service 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| as_service-0.1.1-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details |
Release files / as_service-0.1.1-py3-none-win_amd64.whl
| Download URL | as_service-0.1.1-py3-none-win_amd64.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
d41b8b0ee9e111b6dc1ceb860dcaa11a5aaf612a85ac8bbd5698e3e0c1de3355
|
|
BLAKE2b-256 checksum How to use checksums |
9e587d65e700afcd226753199c7ee6db163a6756fe33197353da6072d55ea798
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.13
|