-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from usnistgov/update_requirements
Add requirements-all for docs build
- Loading branch information
Showing
96 changed files
with
1,189 additions
and
805 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 |
---|---|---|
|
@@ -39,9 +39,17 @@ | |
import io | ||
import numpy as np | ||
from distutils.util import strtobool | ||
except ImportError: | ||
except (ModuleNotFoundError,ImportError): | ||
warnings.warn('Plotting imports failed! Live data plotting will not work on this server.',stacklevel=2) | ||
|
||
try: | ||
import socket | ||
from zeroconf import IPVersion, ServiceInfo, Zeroconf | ||
_ADVERTISE_ZEROCONF=True | ||
except (ModuleNotFoundError,ImportError): | ||
warnings.warn('Could not import zeroconf! Network autodiscovery will not work on this server.',stacklevel=2) | ||
_ADVERTISE_ZEROCONF=False | ||
|
||
class APIServer: | ||
def __init__(self,name,data = None,experiment='Development',contact='[email protected]',index_template='index.html',new_index_template='index-new.html',plot_template='simple-bokeh.html'): | ||
self.name = name | ||
|
@@ -88,16 +96,51 @@ def reset_queue_daemon(self,driver=None): | |
self.queue_daemon.terminate() | ||
self.create_queue(self.driver) | ||
return 'Success',200 | ||
|
||
def advertise_zeroconf(self,**kwargs): | ||
if 'port' not in kwargs.keys(): | ||
port = 5000 | ||
else: | ||
port = kwargs['port'] | ||
self.zeroconf_info = ServiceInfo( | ||
"_aflhttp._tcp.local.", | ||
f"{self.queue_daemon.driver.name}._aflhttp._tcp.local.", | ||
addresses=[socket.inet_aton("127.0.0.1")], | ||
port=port, | ||
properties= { | ||
'system_info': 'AFL', | ||
'driver_name': self.queue_daemon.driver.name, | ||
'server_name': self.name, | ||
'contact': self.contact, | ||
'driver_parents': repr(self.queue_daemon.driver.__class__.__mro__) | ||
# other stuff here, AFL system serial, etc. | ||
}, | ||
server=f"{socket.gethostname()}.local.", | ||
) | ||
self.zeroconf = Zeroconf(ip_version=IPVersion.All) | ||
self.zeroconf.register_service(self.zeroconf_info) | ||
print("Started mDNS service advertisement.") | ||
def run(self,**kwargs): | ||
if self.queue_daemon is None: | ||
raise ValueError('create_queue must be called before running server') | ||
self.app.run(**kwargs) | ||
if _ADVERTISE_ZEROCONF: | ||
try: | ||
self.advertise_zeroconf(**kwargs) | ||
except Exception as e: | ||
print(f'failed while trying to start zeroconf {e}, continuing') | ||
try: | ||
self.app.run(**kwargs) | ||
finally: | ||
if _ADVERTISE_ZEROCONF: | ||
self.zeroconf.unregister_service(self.zeroconf_info) | ||
self.zeroconf.close() | ||
|
||
def run_threaded(self,start_thread=True,**kwargs): | ||
if self.queue_daemon is None: | ||
raise ValueError('create_queue must be called before running server') | ||
|
||
if _ADVERTISE_ZEROCONF: | ||
self.advertise_zeroconf(**kwargs) | ||
|
||
|
||
thread = threading.Thread(target=self.app.run,daemon=True,kwargs=kwargs) | ||
if start_thread: | ||
thread.start() | ||
|
@@ -631,4 +674,4 @@ def login_test(self): | |
server = APIServer('TestServer') | ||
server.add_standard_routes() | ||
server.create_queue(DummyDriver()) | ||
server.run(host='0.0.0.0',debug=True) | ||
server.run(host='0.0.0.0',debug=False) |
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
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
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
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
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
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
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
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
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
Oops, something went wrong.