sgn.control
¶
HTTPControl
¶
Bases: SignalEOS
flowchart TD
sgn.control.HTTPControl[HTTPControl]
sgn.sources.SignalEOS[SignalEOS]
sgn.sources.SignalEOS --> sgn.control.HTTPControl
click sgn.control.HTTPControl href "" "sgn.control.HTTPControl"
click sgn.sources.SignalEOS href "" "sgn.sources.SignalEOS"
A context manager that stores a bottle app running in a separate thread.
If you have a pipeline called p do,
with HTTPControl() as control: p.run()
The bottle process is started and stoped on enter and exit. This class inherits SignalEOS context manager actions too, becuase otherwise bottle will respond to ctrl+C and generally you want to deal with both signals and bottle contexts in a coherent way when executing a pipeline, so this implementation tries to do that.
Source code in src/sgn/control.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
bound_port
property
¶
The port the bottle server actually bound to (resolved after enter).
exchange_state(name, state_dict)
classmethod
¶
Automate the common task of reading and writing state to an element. name is the name of an element (which is the key of both get and post slots) and state_dict is a dictionary of state variables with correct types that can be coerced out of json. This will mostly work out of the box for simple data types like ints and floats and strings, but complicated data will probably not work. FIXME consider supporting more complex types if it comes up.
HTTPControl.exchange_state(
Source code in src/sgn/control.py
HTTPControlSinkElement
dataclass
¶
Bases: SinkElement, HTTPControl
flowchart TD
sgn.control.HTTPControlSinkElement[HTTPControlSinkElement]
sgn.base.SinkElement[SinkElement]
sgn.base.ElementLike[ElementLike]
sgn.base.UniqueID[UniqueID]
sgn.control.HTTPControl[HTTPControl]
sgn.sources.SignalEOS[SignalEOS]
sgn.base.SinkElement --> sgn.control.HTTPControlSinkElement
sgn.base.ElementLike --> sgn.base.SinkElement
sgn.base.UniqueID --> sgn.base.ElementLike
sgn.control.HTTPControl --> sgn.control.HTTPControlSinkElement
sgn.sources.SignalEOS --> sgn.control.HTTPControl
click sgn.control.HTTPControlSinkElement href "" "sgn.control.HTTPControlSinkElement"
click sgn.base.SinkElement href "" "sgn.base.SinkElement"
click sgn.base.ElementLike href "" "sgn.base.ElementLike"
click sgn.base.UniqueID href "" "sgn.base.UniqueID"
click sgn.control.HTTPControl href "" "sgn.control.HTTPControl"
click sgn.sources.SignalEOS href "" "sgn.sources.SignalEOS"
A lightweight subclass of SinkElement that defaults to setting up post and get routes based on the provided element name. Each route is backed by a single-value slot: posts always succeed (replacing any prior value), gets read the held value without consuming it.
Source code in src/sgn/control.py
HTTPControlSourceElement
dataclass
¶
Bases: SourceElement, HTTPControl
flowchart TD
sgn.control.HTTPControlSourceElement[HTTPControlSourceElement]
sgn.base.SourceElement[SourceElement]
sgn.base.ElementLike[ElementLike]
sgn.base.UniqueID[UniqueID]
sgn.control.HTTPControl[HTTPControl]
sgn.sources.SignalEOS[SignalEOS]
sgn.base.SourceElement --> sgn.control.HTTPControlSourceElement
sgn.base.ElementLike --> sgn.base.SourceElement
sgn.base.UniqueID --> sgn.base.ElementLike
sgn.control.HTTPControl --> sgn.control.HTTPControlSourceElement
sgn.sources.SignalEOS --> sgn.control.HTTPControl
click sgn.control.HTTPControlSourceElement href "" "sgn.control.HTTPControlSourceElement"
click sgn.base.SourceElement href "" "sgn.base.SourceElement"
click sgn.base.ElementLike href "" "sgn.base.ElementLike"
click sgn.base.UniqueID href "" "sgn.base.UniqueID"
click sgn.control.HTTPControl href "" "sgn.control.HTTPControl"
click sgn.sources.SignalEOS href "" "sgn.sources.SignalEOS"
A lightweight subclass of SourceElement that defaults to setting up post and get routes based on the provided element name. Each route is backed by a single-value slot: posts always succeed (replacing any prior value), gets read the held value without consuming it.
Source code in src/sgn/control.py
HTTPControlTransformElement
dataclass
¶
Bases: TransformElement, HTTPControl
flowchart TD
sgn.control.HTTPControlTransformElement[HTTPControlTransformElement]
sgn.base.TransformElement[TransformElement]
sgn.base.ElementLike[ElementLike]
sgn.base.UniqueID[UniqueID]
sgn.control.HTTPControl[HTTPControl]
sgn.sources.SignalEOS[SignalEOS]
sgn.base.TransformElement --> sgn.control.HTTPControlTransformElement
sgn.base.ElementLike --> sgn.base.TransformElement
sgn.base.UniqueID --> sgn.base.ElementLike
sgn.control.HTTPControl --> sgn.control.HTTPControlTransformElement
sgn.sources.SignalEOS --> sgn.control.HTTPControl
click sgn.control.HTTPControlTransformElement href "" "sgn.control.HTTPControlTransformElement"
click sgn.base.TransformElement href "" "sgn.base.TransformElement"
click sgn.base.ElementLike href "" "sgn.base.ElementLike"
click sgn.base.UniqueID href "" "sgn.base.UniqueID"
click sgn.control.HTTPControl href "" "sgn.control.HTTPControl"
click sgn.sources.SignalEOS href "" "sgn.sources.SignalEOS"
A lightweight subclass of TransformElement that defaults to setting up post and get routes based on the provided element name. Each route is backed by a single-value slot: posts always succeed (replacing any prior value), gets read the held value without consuming it.
Source code in src/sgn/control.py
Slot
¶
A thread-safe single-value mailbox.
Replaces the original Queue(maxsize=1) + drain-then-put pattern, which
was not atomic and could deadlock under concurrent access. set always
replaces the current value (never blocks), get reads without consuming,
and take reads-and-clears.
Downstream packages (e.g. sgnl) construct Slot directly to register
extra routes on the shared HTTPControl.post_slots / get_slots dicts::
HTTPControl.post_slots["my_route"] = Slot()
Source code in src/sgn/control.py
run_bottle_app(post_slots=None, get_slots=None, host='localhost', port=8080, tag=None, port_event=None)
¶
A function that sets up post and get slots for a bottle server running on host:port.
post_slots is a dictionary whose keys define routes of the form http://host:port/tag/post/key. The values are Slot objects where the data that is posted by the external request will be stored.
get_slots define the inverse, e.g., http://host:port/tag/get/key and the Slot values are where the data for the request comes from.