Python application component initialization system
Project description
systemPY
Python application component initialization system
Full documantation is available at Read the Docs
The problem
The regular application contain many atomic components. Asyncio makes theirs initializing a little bit complicated. It's OK, when you have single entrypoint and initialize your application components via your framework. While you add new components to your application iteratively, you don't see any problem
When you create any new entrypoint, you have to think a lot, how to initialize application components again, which callbacks should be called and in which order. But it's a half of the problem! You have to implement also graceful shutdown
The most painful part is one-time scripts. It's kind of The Banana Gorilla Problem: you wanted a banana but you have to initialize a gorilla holding the banana and the entire jungle, and then graceful shutdown it
Solution
This library allows you to implement application startup and shutdown in
declarative way. You have to implement a class for each your component,
write the startup and shutdown code. Then combine required components as
mixins into the current application Unit
class. Then create an instance
and pass dependencies as keyword arguments. In case it's daemon run
instance.run_sync()
methed
Basic principles
There are 6 most significant stages of the application lifecycle:
-
on_init
executes exactly once on application startup -
pre_startup
is called before event loop startup -
on_startup
is called exactly when event loop started -
on_shutdown
is called when application is going shutdown or reload but event loop still working -
post_shutdown
is called after event loop stopped or drained. When application is going to reload, then it should be calledpre_startup
-
on_exit
executes exactly once when application is stopping
You may to create Unit
classes for each your application component where you
may put your code. Then you may combine these Unit
class mixins into the
current worker class, which aggregate your defined callbacks and run in the
right order. Depending on application type, these callbacks may be called by
primary application or by you are
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file systemPY-0.0.16.tar.gz
.
File metadata
- Download URL: systemPY-0.0.16.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.9.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ecad5aaf4254eb4f11819cbfea83c03a1010e69893a1ea13196b1bdb1cfbb3c |
|
MD5 | aaf268e11f31d6730ecad66f156fb99e |
|
BLAKE2b-256 | 62f1fde6c4ac36bd95617bb246a18b8f256d20dfaac07f83aa16b15297b4e17c |
File details
Details for the file systemPY-0.0.16-py3-none-any.whl
.
File metadata
- Download URL: systemPY-0.0.16-py3-none-any.whl
- Upload date:
- Size: 25.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.9.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | de33489b8cc9af71d4fddf8c03f222032af9dbe7141412127a0dc4554c5c1491 |
|
MD5 | 7718a8b3142a4a1ce97646c9b7c75657 |
|
BLAKE2b-256 | 9d15e8b522c39159582f7177bcffb1baaf2e3dd2d4d32600b00b2d6ff4e0a8cd |