Skip to content

Commit

Permalink
Merge pull request #132 from Geson-anko/BaseApp/getThreadSharedValue
Browse files Browse the repository at this point in the history
Base app/get thread shared value
  • Loading branch information
Geson-anko committed May 19, 2022
2 parents 1c36061 + fe29f08 commit 00ef9be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 4 additions & 1 deletion JarvisEngine/apps/base_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,7 @@ def _get_shared_value(self, name:str, for_thread:bool) -> Any:
def getProcessSharedValue(self, name:str) -> Any:
"""Interface of `_get_shared_value(...,for_thread=False)`"""
return self._get_shared_value(name, False)


def getThreadSharedValue(self, name:str) -> Any:
"""Interface of `_get_shared_value(...,for_thread=True)`"""
return self._get_shared_value(name, True)
20 changes: 19 additions & 1 deletion tests/apps/test_base_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,22 @@ def test_getProcessSharedValue():
assert MainApp.getProcessSharedValue(".aaa") == 10
assert MainApp.getProcessSharedValue("MAIN.App0.bbb") == True
assert App0.getProcessSharedValue("..App1.ccc") == "apple"
assert App1.getProcessSharedValue(".App1_1.ddd") == 1.0
assert App1.getProcessSharedValue(".App1_1.ddd") == 1.0

@_cd_project_dir
def test_getThreadSharedValue():
name = "MAIN"
config = project_config.MAIN
app_dir = PROJECT_DIR
MainApp = base_app.BaseApp(name, config, engine_config,project_config,app_dir)
fdwl_thread= FolderDict_withLock(sep=".")
MainApp.set_thread_shared_values_to_all_apps(fdwl_thread)

App0 = MainApp.child_apps["App0"]

# Thread shared value
MainApp.addThreadSharedValue("eee",False)
App0.addThreadSharedValue("fff",20)

assert MainApp.getThreadSharedValue("..MAIN.eee") == False
assert App0.getThreadSharedValue("MAIN.App0.fff") == 20

0 comments on commit 00ef9be

Please sign in to comment.