Device Manger worlker module¶
This module contains plumbing that allows
Here we have defined a wrapper that creates device on separate process and allows to all methods of this device
-
class
silf.backend.commons.device_manager._worker.DeviceWorkerWrapper(device_id, device_constructor, multiprocess=<object object>, config_file=None)¶ Bases:
objectThis a wrapper for the device it launched it works that way:
- Creates a process on this machine
- Constructs the device inside this process
- Enables more-or-less transparent operations on the remote device.
- Enables us to kill the remote process when really needed
Support for remote process should be transparent, with one important exception: all mehods are asynchroneous, for example when making a
get_results()call you actually end up doing:- Sheduling a request to refresh results from remote side
- Reading all messages from input queue
- Returning last used results
-
append_results(results)¶
-
auto_pull_results= None¶ If true the experiment will automatically pull results.
-
cleanup(callback=None)¶ Schedules a task to turn off the device kill the remote thread. :return: task_id
-
config_file= None¶ Congig parser instance for this experiment.
-
device_constructor= None¶ Remote process.
-
execute_task(task, callback=None, sync=False)¶ Schedules task execution on remote process.
Parameters: - task – Task to be executed
- callback – A callable that will be called upon completion of this
task. It should accept single argument: instance of
TaskResponsethat contains the results for this task.
Returns: Task id
-
in_queue= None¶ Queue that contains responses for tasks from remote process. Contains instances of
TaskResponse.
-
kill(wait_time=2)¶ Kills remote process, optionally waiting. This method will block until remote process is killed.
Parameters: wait_time (float) – Wait time in seconds. If wait_time is None, then terminate process without additional waiting. Returns: None
-
logger¶
-
loop_iteration(max_read=None)¶ Reads all messages from the input queue, updating self.state and self.results.
Returns: None
-
out_queue= None¶ Queue that contains tasks to be executed on remote process, Should contain instances of
QueueTask, though any callable with proper signature will do.
-
ping_results(callback=None, sync=False)¶ Schedules getting of new results/ :param callback: See
execute_task()
-
pop_results(sync=False)¶ Schedules getting of new results and then returns cached results. :return:
-
process_alive¶ Checks if remote process is alive.
Returns: Trueif remote process is alive,FalseotherwiseReturn type: bool
-
purge_queue(queue)¶ Removes all pending operations from a queue. :return: None`
-
start(callback=None, sync=False)¶
-
start_subprocess()¶ Starts subprocess attached to this instance.
-
state¶ Returns most recent state of remote process. :return: State :rtype: str
-
stop(callback=None, sync=True)¶ Schedules a task to stop the device. :param callback: See
execute_task():return: Returns task id
-
wait_for_response(task_id)¶ Gets responses from queue until response for task with id equal to task_id param.
Note
This method will block until we get response for task_id
Warning
It may introduce deadlock if response for task_id has already been processed. To be sure it will not cause deadlock please execute this function just after sheduling the task. Much safer solution is to attach a callback for particular task, please see
execute_task().Parameters: task_id – Task id we are looking for. Returns: Response for task with id equal to task_id.
-
silf.backend.commons.device_manager._worker.set_multiprocessing(do_multiprocess)¶
-
silf.backend.commons.device_manager._worker.reset_multiprocessing()¶
-
silf.backend.commons.device_manager._worker.start_worker_interactive(device_id, device_class, auto_pull_results=True, configure_logging=True, config_file=None)¶