Skip to content

Reoccurrence of #2322? Multiprocessing spawn in python 3 does not work on macOS #4865

Description

@andyfaff

Description of the issue

There looks to be a reoccurrence of #2322 on macOS with spawn + multiprocessing. I came across this issue with a package that I develop (that uses PyQt5). When I try and use multiprocessing within my program I get multiple GUI windows displaying. This has only happened since building the executable with Py3.8 (spawn is default), it doesn't happen with Py3.7 (fork is default). I tried using the MWE from #2322 and it is failing on my computer.

Context information

macOS 10.13.6
Python 3.8.2 (from conda)
PyInstaller: tip of the development branch (3.6)

  • [Y] start with clean installation
  • [Y] use the latest development version
  • [Y] Run your frozen program from a command window (shell) — instead of double-clicking on it
  • [Y] Package your program in --onedir mode
  • [Y] Package without UPX, say: use the option --noupx or set upx=False in your .spec-file
  • [Y] Repackage you application in verbose/debug mode. For this, pass the option --debug to pyi-makespec or pyinstaller or use EXE(..., debug=1, ...) in your .spec file.

A minimal example program which shows the error

Running test.py from bash is fine, and gives the expected result. However, running the packaged executable results in processes spawning continuously.

test.py

import sys
from multiprocessing import freeze_support, set_start_method, Process

def test():
    print('In subprocess')

if __name__ == '__main__':
    print(sys.argv,)
    freeze_support()
    set_start_method('spawn')

    print('In main')
    proc = Process(target=test)
    proc.start()
    proc.join()

test.spec

# -*- mode: python -*-

block_cipher = None


a = Analysis(['test.py'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='test',
          debug=True,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='test')

Stacktrace / full error message

Log at https://gist.github.com/andyfaff/c8402452e7bf4d27a1c86c1c486a736e

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions