forked from M-Labs/artiq
Compare commits
2 Commits
13a36bf911
...
dae0586cc8
Author | SHA1 | Date |
---|---|---|
Simon Renblad | dae0586cc8 | |
Sébastien Bourdeauducq | 329e7189cc |
|
@ -0,0 +1,20 @@
|
|||
from artiq.experiment import *
|
||||
|
||||
|
||||
class InteractiveDemo(EnvExperiment):
|
||||
def build(self):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
print("Waiting for user input...")
|
||||
with self.interactive() as interactive:
|
||||
interactive.setattr_argument("number", NumberValue(42e-6,
|
||||
unit="us",
|
||||
precision=4))
|
||||
interactive.setattr_argument("integer", NumberValue(42,
|
||||
step=1, precision=0))
|
||||
interactive.setattr_argument("string", StringValue("Hello World"))
|
||||
print("Done! Values:")
|
||||
print(interactive.number, type(interactive.number))
|
||||
print(interactive.integer, type(interactive.integer))
|
||||
print(interactive.string)
|
|
@ -2,6 +2,7 @@ from collections import OrderedDict
|
|||
from inspect import isclass
|
||||
from contextlib import contextmanager
|
||||
from types import SimpleNamespace
|
||||
import threading
|
||||
|
||||
from sipyco import pyon
|
||||
|
||||
|
@ -262,6 +263,7 @@ class HasEnvironment:
|
|||
self.__in_build = True
|
||||
self.build(*args, **kwargs)
|
||||
self.__in_build = False
|
||||
self.__interactive_semaphore = threading.Semaphore()
|
||||
|
||||
def register_child(self, child):
|
||||
self.children.append(child)
|
||||
|
@ -349,7 +351,10 @@ class HasEnvironment:
|
|||
namespace.setattr_argument = setattr_argument
|
||||
yield namespace
|
||||
del namespace.setattr_argument
|
||||
if not self.__interactive_semaphore.acquire(blocking=False):
|
||||
raise RuntimeError("concurrent calls to interactive with the same RID is not supported")
|
||||
argdict = self.__argument_mgr.get_interactive(interactive_arglist, title)
|
||||
self.__interactive_semaphore.release()
|
||||
for key, value in argdict.items():
|
||||
setattr(namespace, key, value)
|
||||
|
||||
|
|
Loading…
Reference in New Issue