-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Example in Support of Issue #297
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
from time import sleep | ||
from cement.core.exc import CaughtSignal | ||
from cement.core import hook | ||
from cement.core.foundation import CementApp | ||
from cement.core.controller import CementBaseController, expose | ||
|
||
def print_foo(app): | ||
print("Foo => %s" % app.config.get('myapp', 'foo')) | ||
print("Example Foo => %s" % app.config.get('example', 'foo')) | ||
|
||
|
||
class Base(CementBaseController): | ||
class Meta: | ||
label = 'base' | ||
|
||
@expose(hide=True) | ||
def default(self): | ||
print('Inside Base.default()') | ||
|
||
# simulate a long running process | ||
while True: | ||
sleep(30) | ||
|
||
class MyApp(CementApp): | ||
class Meta: | ||
label = 'myapp' | ||
base_controller = Base | ||
extensions = ['reload_config'] | ||
|
||
|
||
with MyApp() as app: | ||
# run this anytime the configuration has changed | ||
hook.register('post_reload_config', print_foo) | ||
|
||
try: | ||
app.run() | ||
except CaughtSignal as e: | ||
# maybe do something... but catch it regardless so app.close() is | ||
# called when exiting `with` cleanly. | ||
print(e) |