neurolang.utils.server.queries module¶
- class neurolang.utils.server.queries.LRUCacheDict(cache_len: int = 15, *args, **kwargs)¶
Bases:
OrderedDict
Dict with a limited length, ejecting LRUs as needed.
Methods
clear
()copy
()fromkeys
(/, iterable[, value])Create a new ordered dictionary with keys from iterable and values set to value.
get
(key[, default])Return the value for key if key is in the dictionary, else default.
items
()keys
()move_to_end
(/, key[, last])Move an existing element to the end (or beginning if last is false).
pop
(k[,d])value.
popitem
(/[, last])Remove and return a (key, value) pair from the dictionary.
setdefault
(/, key[, default])Insert key with a value of default if key is not in the dictionary.
update
([E, ]**F)If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
values
()
- class neurolang.utils.server.queries.NeurolangQueryManager(options: Dict[NeurolangEngineConfiguration, int], cache_len: int = 15)¶
Bases:
object
Class to manage execution of queries and keep track of results.
This class is initialized with a dict of NeurolangEngineConfiguration that defines which Neurolang engine to create and how many. The NeurolangQueryManager creates a pool of thread workers (as many as there are engines) to execute the queries that are submited.
It also keeps track of results in memory, in a results_cache which is a dict of uuid -> Future.
Methods
cancel
(uuid)Attempt to cancel the execution.
get_atlas
(engine_type)Get the atlas for a given engine type.
get_result
(uuid)Fetch the results for a query execution.
get_symbols
(engine_type)Request the symbols table for a given engine.
submit_query
(uuid, query, engine_type)Submit a query to one of the available engines / workers.
- cancel(uuid: str) bool ¶
Attempt to cancel the execution. If the call is currently being executed or finished running and cannot be cancelled then the method will return False, otherwise the call will be cancelled and the method will return True.
- Parameters:
- uuidstr
the task execution id
- Returns:
- bool
True if cancelled
- get_atlas(engine_type: str) Nifti1Image ¶
Get the atlas for a given engine type.
- Parameters:
- engine_typestr
the engine type
- Returns:
- nibabel.Nifti1Image
the mni atlas
- get_result(uuid: str) Future ¶
Fetch the results for a query execution.
- Parameters:
- uuidstr
the query id
- Returns:
- Future
the Future results of the execution task.
- get_symbols(engine_type: str) Future ¶
Request the symbols table for a given engine. If the symbols table for this engine type is present in cache, then this is returned, otherwise a job to fetch the symbols table is dispatched to the threadpool executor.
- Parameters:
- engine_typestr
the engine type.
- Returns:
- Future
the Future result for the symbols query
- submit_query(uuid: str, query: str, engine_type: str) Future ¶
Submit a query to one of the available engines / workers.
- Parameters:
- uuidstr
the uuid for the query.
- querystr
the datalog query to execute.
- engine_typestr
the type of engine to use for solving the query.
- Returns:
- Future
a future result for the query execution.