Skip to content

Commit

Permalink
Adding Example in Support of Issue #297
Browse files Browse the repository at this point in the history
  • Loading branch information
derks committed May 5, 2015
1 parent b5191a7 commit 53f72fc
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions examples/reload_config/myapp.py
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)

0 comments on commit 53f72fc

Please sign in to comment.