From 18f08a91369bf01421d36bdac2fe7d998d514808 Mon Sep 17 00:00:00 2001 From: chenjian Date: Fri, 2 Dec 2022 14:47:07 +0800 Subject: [PATCH] Set prefered multiprocessing startup method (#2152) * set prefered multiprocessing startup method * set prefered multiprocessing startup method --- paddlehub/commands/utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/paddlehub/commands/utils.py b/paddlehub/commands/utils.py index 4ef4db46..01c6cc41 100644 --- a/paddlehub/commands/utils.py +++ b/paddlehub/commands/utils.py @@ -12,9 +12,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - -from typing import Any from collections import defaultdict +from typing import Any def _CommandDict(): @@ -64,6 +63,13 @@ def execute(): status(int) : Result of the command execution. 0 for a success and 1 for a failure. ''' import sys + import multiprocessing + try: + multiprocessing.set_start_method( + 'fork' + ) # In paddlehub, functions like gradio app need multiprocess supported, and 'fork' is our prefered start method. + except Exception: + pass # If can not set 'fork', maintain the default start method com = _commands for idx, _argv in enumerate(['hub'] + sys.argv[1:]): if _argv not in com: -- GitLab