Skip to content

Commit

Permalink
feat: clarify the unexpected behavior in standalone mode regardings t…
Browse files Browse the repository at this point in the history
…he main script
  • Loading branch information
trgiangdo committed Jul 24, 2024
1 parent 21f4b31 commit 3e64eb4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions docs/manuals/userman/configuration/job-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,14 @@ integer value greater than 1. That starts each `Job^` in a dedicated process wit
The default value of *max_nb_of_workers* is 2.

!!! warning
In *standalone* mode, it's a good practice to protect the main code with the `if __name__ == "__main":`
condition. By doing this, the code will not be re-executed when the subprocesses are spawned.

In *standalone* mode, when a subprocess is spawned, the code is re-executed except
for the code inside the `if __name__ == "__main__":` condition. This can lead to
unexpected behavior if the code is not protected.

Therefore, it's a good practice to protect the main code with the `if __name__ == "__main":`
condition in your Taipy application main script. By doing this, the code will not be re-executed
when the subprocesses are spawned.

For example, the following configuration will allow Taipy to run up to eight `Job^`s
simultaneously:
Expand Down
10 changes: 8 additions & 2 deletions docs/tutorials/scenario_management/5_job_execution/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ This line of code alters the execution mode. Setting it to *standalone* makes Ta
In this configuration, a maximum of two tasks can run simultaneously.

!!! warning
In *standalone* mode, it's a good practice to protect the main code with the `if __name__ == "__main":`
condition. By doing this, the code will not be re-executed when the subprocesses are spawned.

In *standalone* mode, when a subprocess is spawned, the code is re-executed except
for the code inside the `if __name__ == "__main__":` condition. This can lead to
unexpected behavior if the code is not protected.

Therefore, it's a good practice to protect the main code with the `if __name__ == "__main":`
condition in your Taipy application main script. By doing this, the code will not be re-executed
when the subprocesses are spawned.

```python
Config.configure_job_executions(mode="standalone", max_nb_of_workers=2)
Expand Down

0 comments on commit 3e64eb4

Please sign in to comment.