Mercurial > hg > orthanc-book
annotate Sphinx/source/plugins/python/periodic-execution.py @ 1034:bbcec5f44c34
PG 6.0
author | Alain Mazy <am@osimis.io> |
---|---|
date | Thu, 08 Feb 2024 16:46:35 +0100 |
parents | ba2403ebd4b7 |
children |
rev | line source |
---|---|
704
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 import orthanc |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 import threading |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 TIMER = None |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 def Hello(): |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 global TIMER |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 TIMER = None |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 orthanc.LogWarning("In Hello()") |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 # Do stuff... |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 TIMER = threading.Timer(1, Hello) # Re-schedule after 1 second |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 TIMER.start() |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 def OnChange(changeType, level, resource): |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 if changeType == orthanc.ChangeType.ORTHANC_STARTED: |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 orthanc.LogWarning("Starting the scheduler") |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 Hello() |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 elif changeType == orthanc.ChangeType.ORTHANC_STOPPED: |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 if TIMER != None: |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 orthanc.LogWarning("Stopping the scheduler") |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 TIMER.cancel() |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
ba2403ebd4b7
moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 orthanc.RegisterOnChangeCallback(OnChange) |