cengal.parallel_execution.multiprocess.multiprocess_testing

 1#!/usr/bin/env python
 2# coding=utf-8
 3
 4# Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>
 5# 
 6# Licensed under the Apache License, Version 2.0 (the "License");
 7# you may not use this file except in compliance with the License.
 8# You may obtain a copy of the License at
 9# 
10#     http://www.apache.org/licenses/LICENSE-2.0
11# 
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18from multiprocessing import Process, Queue
19import os
20from cengal.parallel_execution.multiprocess.multiprocessing_task_runner import *
21import sys
22
23"""
24Module Docstring
25Docstrings: http://www.python.org/dev/peps/pep-0257/
26"""
27
28__author__ = "ButenkoMS <gtalk@butenkoms.space>"
29__copyright__ = "Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>"
30__credits__ = ["ButenkoMS <gtalk@butenkoms.space>", ]
31__license__ = "Apache License, Version 2.0"
32__version__ = "4.4.1"
33__maintainer__ = "ButenkoMS <gtalk@butenkoms.space>"
34__email__ = "gtalk@butenkoms.space"
35# __status__ = "Prototype"
36__status__ = "Development"
37# __status__ = "Production"
38
39
40def funct(inputData):
41    result = inputData[0] / inputData[1]
42    return result
43
44if __name__ == '__main__':
45    process0 = SubprocessWorker(funct)
46    process1 = SubprocessWorker(funct)
47    process0.start()
48    process1.start()
49    data0 = (3, 2)
50    data1 = (5, 0)
51    process0.send_data_to_subprocess(data0)
52    process1.send_data_to_subprocess(data1)
53    try:
54        answer0 = process0.get_answer_from_subprocess()
55        print('answer0 = ', answer0)
56        answer1 = process1.get_answer_from_subprocess()
57        print('answer1 = ', answer1)
58    except:
59        print()
60        print('<<< BROAD EXCEPTION:')
61        print(sys.exc_info()[0])
62        print(sys.exc_info()[1])
63        print('>>>')
64        raise
65    process0.stop()
66    process1.stop()
67
68
69#class Multi_Test:
70#
71#    def __init__(self, queue):
72#        self.queue = queue
73#
74#    def info(self, title):
75#        print(title)
76#        print('module name:', __name__)
77#        if hasattr(os, 'getppid'):  # only available on Unix
78#            print('parent process:', os.getppid())
79#        print('process id:', os.getpid())
80#
81#    def f(self, name):
82#        self.info('function f')
83#        print('hello', name[1])
84#        name[0].put('hello')
85#
86#    def start_process(self, ):
87#        self.info('main line')
88#        p = Process(target=self.f, args=((self.queue, 'bob'),))
89#        p.start()
90#        p.join()
91#        print(self.queue.get())
92#
93#if __name__ == '__main__':
94#    q = Queue()
95#    mp = Multi_Test(q)
96#    mp.start_process()
def funct(inputData):
41def funct(inputData):
42    result = inputData[0] / inputData[1]
43    return result