blob: 901cffb4e346ee51791d09c4de53bde6e398bbf6 [file] [log] [blame]
George Keishingd942b512017-06-06 14:34:55 -05001#!/usr/bin/env python
2
3r"""
4This module contains keyword functions to support multiprocessing
5execution of keywords where generic robot keywords don't support.
6
7"""
8
9from robot.libraries.BuiltIn import BuiltIn
10from multiprocessing import Process, Manager
11import os
12import gen_print as gp
13
14
15###############################################################################
16def execute_keyword(keyword_name, return_dict):
17 r"""
18 Execute a robot keyword.
19 In addition to running the caller's keyword, this function will:
20 - Add an entry to the return_dict
21
22 Description of argument(s):
23 keyword_name Keyword name to be executed.
George Keishing84d089f2017-07-17 09:33:01 -050024 return_dict A dictionary consisting of pid/process status for the
George Keishingd942b512017-06-06 14:34:55 -050025 keys/values. This function will append a new entry to
26 this dictionary.
27 """
28
29 pid = os.getpid()
George Keishing84d089f2017-07-17 09:33:01 -050030 status = BuiltIn().run_keyword_and_return_status(keyword_name)
George Keishingd942b512017-06-06 14:34:55 -050031
George Keishing84d089f2017-07-17 09:33:01 -050032 # Build PID:<status> dictionary.
33 return_dict[str(pid)] = str(status)
George Keishingd942b512017-06-06 14:34:55 -050034
35###############################################################################
36
37
38###############################################################################
39def execute_process(num_process, keyword_name):
40 r"""
41 Execute a robot keyword via multiprocessing process.
42
43 Description of argument(s):
44 num_process Number of times keyword to be executed.
45 keyword_name Keyword name to be executed.
46 """
47
48 manager = Manager()
49 return_dict = manager.dict()
50 process_list = []
51
52 # Append user-defined times process needed to execute.
53 for ix in range(int(num_process)):
54 task = Process(target=execute_keyword, args=(keyword_name, return_dict))
55 process_list.append(task)
56 task.start()
57
58 # Wait for process to complete.
59 for task in process_list:
60 task.join()
61
62 # Return function return codes.
63 return return_dict
64
65###############################################################################