Mercurial > hg > orthanc-book
comparison Sphinx/source/plugins/python/periodic-execution.py @ 704:ba2403ebd4b7
moving python samples in separate files (3)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 11 Jun 2021 10:24:08 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
703:a589668768d7 | 704:ba2403ebd4b7 |
---|---|
1 import orthanc | |
2 import threading | |
3 | |
4 TIMER = None | |
5 | |
6 def Hello(): | |
7 global TIMER | |
8 TIMER = None | |
9 orthanc.LogWarning("In Hello()") | |
10 # Do stuff... | |
11 TIMER = threading.Timer(1, Hello) # Re-schedule after 1 second | |
12 TIMER.start() | |
13 | |
14 def OnChange(changeType, level, resource): | |
15 if changeType == orthanc.ChangeType.ORTHANC_STARTED: | |
16 orthanc.LogWarning("Starting the scheduler") | |
17 Hello() | |
18 | |
19 elif changeType == orthanc.ChangeType.ORTHANC_STOPPED: | |
20 if TIMER != None: | |
21 orthanc.LogWarning("Stopping the scheduler") | |
22 TIMER.cancel() | |
23 | |
24 orthanc.RegisterOnChangeCallback(OnChange) |