Implemented basic threaded tasks for long-running functionality
This commit is contained in:
parent
4a09727e65
commit
a40cb9b9f6
10 changed files with 328 additions and 14 deletions
|
|
@ -1,6 +1,8 @@
|
|||
import random
|
||||
import time
|
||||
from openflexure_microscope.plugins import MicroscopePlugin
|
||||
|
||||
from .api import IdentifyAPI, HelloWorldAPI
|
||||
from .api import IdentifyAPI, HelloWorldAPI, LongRunningAPI
|
||||
|
||||
|
||||
class Plugin(MicroscopePlugin):
|
||||
|
|
@ -11,6 +13,7 @@ class Plugin(MicroscopePlugin):
|
|||
api_views = {
|
||||
'/identify': IdentifyAPI,
|
||||
'/hello': HelloWorldAPI,
|
||||
'/long_running': LongRunningAPI,
|
||||
}
|
||||
|
||||
def identify(self):
|
||||
|
|
@ -27,4 +30,19 @@ class Plugin(MicroscopePlugin):
|
|||
Demonstrate passive method
|
||||
"""
|
||||
|
||||
return "Hello world!"
|
||||
return "Hello world!"
|
||||
|
||||
def long_running(self, t_run):
|
||||
"""
|
||||
Demonstrate a long-running method that requires microscope hardware
|
||||
"""
|
||||
print("Starting a long-running task...")
|
||||
n_array = []
|
||||
|
||||
for _ in range(t_run):
|
||||
n_array.append(random.random())
|
||||
time.sleep(1)
|
||||
|
||||
print("Long-running task finished!")
|
||||
|
||||
return n_array
|
||||
Loading…
Add table
Add a link
Reference in a new issue