Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value sharing (From BaseApp) #109

Open
Geson-anko opened this issue May 17, 2022 · 5 comments
Open

Value sharing (From BaseApp) #109

Geson-anko opened this issue May 17, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@Geson-anko
Copy link
Owner

Value sharing

Regarding #101
Implementing value sharing methods such as setThreadSharedValues and etc...

Originally posted by @Geson-anko in #16 (comment)

@Geson-anko Geson-anko changed the title Value sharing Value sharing (From BaseApp) May 17, 2022
@Geson-anko Geson-anko added the enhancement New feature or request label May 17, 2022
@Geson-anko
Copy link
Owner Author

Geson-anko commented May 17, 2022

process/thread shared values (class attribute)

BaseAppにprocess_shared_values属性とthread_shared_values属性を追加します。
どちらもFolderDict_withLock #115propertyであり、@-_shared_values.setterによるsetterを持ちます。

  • process_shared_values
    初期値はNoneです。 実際には_process_shared_values属性に値を格納しています。
    setterが呼ばれた際にはそのアプリの子アプリーケーションにも値をセットします。
    multiprocessingモジュールによる並列処理の開始後に呼び出してはいけません。

  • thread_shared_values
    基本的に process_shared_valuesと同じですが、setterが呼ばれた際は、自分とthreadで起動する子アプリだけにセットします。
    process_shared_valuesとは対照的に、multiprocessingモジュールによる並列処理の開始後にのみ呼び出し可能です。

@Geson-anko
Copy link
Owner Author

SharedValueHolder

値を共有する際のフォーマットを統一できます。必ずname属性が付くのでaddProcessSharedValuesメソッド等を実装する際にエラーチェックが便利です。ただし、冗長です。

@dataclasss
class SharedValueHolder:
    name:str
    obj: Any

@Geson-anko
Copy link
Owner Author

SharedValueHolder

値を共有する際のフォーマットを統一できます。必ずname属性が付くのでaddProcessSharedValuesメソッド等を実装する際にエラーチェックが便利です。ただし、冗長です。

@dataclasss
class SharedValueHolder:
    name:str
    obj: Any

実装しません。

@Geson-anko
Copy link
Owner Author

Geson-anko commented May 19, 2022

Register Process/Thread Shared Values

Override method.
Register values for sharing inter multiprocessing or threading.

@Geson-anko
Copy link
Owner Author

Geson-anko commented May 19, 2022

get Shared Values (Process/Thread)

process_shared_valuesthread_shared_valuesに格納された共有値を、名前を指定して取得します。
取得方法はファイルパスのようにになっている事を念頭においてください。

Method

名前を指定して取得します。アプリケーションの木構造をもとにドット.区切りのファイルパスのようにオブジェクトは保持されています。規則はパスのようになっています。

  • 絶対パス
    名前の先頭にドット.がない場合、ルートアプリケーションから値を検索し、値を取得します。
  • 相対パス
    名前の先頭に.がある場合、その数だけ自分の相対位置から階層を遡って検索し、値を取得します。

Example

以下のようにアプリケーション全体が構成され、値が共有されているとします。

MAIN
|- App0
|- App1
    |- App1_1
    |- App1_2
[
    "shutdown" = ReadOnlyValue,
    "MAIN.lock" = Lock,
    "MAIN.App0.int_value" = 10,
    "MAIN.App1.str_value" = "apple",
    "MAIN.App1.App1_1.bool_value" = True,
    "MAIN.App1.App1_2.float_value" = 1.0,
]

このとき、MAINアプリケーションにおけるgetSharedValueの振る舞いは次のようになります。

MAIN.getSharedValue("shutdown") -> ReadOnlyValue
MAIN.getSharedValue(".lock") -> Lock
MAIN.getSharedValue("..shutdown") -> ReadOnlyValue
MAIN.getSharedValue(".App0.int_value") -> 10

また、MAIN.App1.App1_1においても以下のようになります。

App1_1.getSharedValue(".bool_value") -> True
App1_1.getSharedValue("MAIN.lock") -> Lock
App1_1.getSharedValue("..str_value") -> "apple"
App1_1.getSharedValue("..App1_2.float_value") -> 1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant