File: pyi_multiprocessing_queue.py

package info (click to toggle)
pyinstaller 6.13.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 11,520 kB
  • sloc: python: 41,347; ansic: 11,334; makefile: 176; sh: 136; xml: 19
file content (55 lines) | stat: -rw-r--r-- 1,593 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#-----------------------------------------------------------------------------
# Copyright (c) 2005-2023, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License (version 2
# or later) with exception for distributing the bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
#-----------------------------------------------------------------------------

import sys
import multiprocessing


class SendEventProcess(multiprocessing.Process):
    def __init__(self, queue):
        multiprocessing.Process.__init__(self)
        self.queue = queue

    def run(self):
        print('SendEventProcess: begin')
        self.queue.put((1, 2))
        print('SendEventProcess: end')


def main(start_method):
    # Set start method
    multiprocessing.set_start_method(start_method)

    # Create a queue, and run a subprocess that fills it with data
    print('Main: begin')
    queue = multiprocessing.Queue()
    process = SendEventProcess(queue)
    process.start()

    results = queue.get()
    print(f'Main: retrieved results: {results}')
    assert results == (1, 2)

    process.join()
    print('Main: end')

    # Ensure process finished successfully
    assert process.exitcode == 0, f"Process exited with non-success code {process.exitcode}!"


if __name__ == '__main__':
    multiprocessing.freeze_support()

    if len(sys.argv) != 2:
        print(f"Usage: {sys.argv[0]} <start-method>")
        sys.exit(1)

    main(sys.argv[1])