Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stopping event loop causes process termination in Sonoma #593

Open
nik012003 opened this issue Feb 11, 2024 · 0 comments
Open

Stopping event loop causes process termination in Sonoma #593

nik012003 opened this issue Feb 11, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@nik012003
Copy link

nik012003 commented Feb 11, 2024

It appears that when fully loading a bundle (such as Foundation), a bouncing python app appears in the dock, and NSApp() now returns an Object instead of None. This makes it impossible to stop the event loop without causing the entire python process to be terminated (due to

if NSApp() is not None:
NSApp().terminate_(self)
).
Here's a minimal PoC:

from Foundation import NSTimer 
from PyObjCTools.AppHelper import runConsoleEventLoop, stopEventLoop
from AppKit import NSApp
import Foundation

# Load any boundle
# This causes an app to appear in the dock on macOS >= 14.0
dir(Foundation)
# This works too:
# objc.loadBundle(
#         'Foundation',
#         globals(),
#         bundle_identifier='com.apple.Foundation',
# )

# Confirm there's an App Running
print(NSApp())

def stopper(self):
    # Here this terminates the app - and thus the whole python process -instead of terminating the event loop
    stopEventLoop()

NSTimer.scheduledTimerWithTimeInterval_repeats_block_(0.3, False, stopper)

runConsoleEventLoop()
print("This should be printed, but it's not")

Output in Sonoma:

$ python3 -u broken.py
<NSApplication: 0x145fe2590>
2024-02-11 21:11:21.024 Python[33482:418681] ApplePersistence=NO
$ sw_vers 
ProductName:            macOS
ProductVersion:         14.2.1
BuildVersion:           23C71

Output in Ventura:

$ python3 -u broken.py
None
This should be printed, but it's not
$ sw_vers 
ProductName:  macOS
ProductVersion:  13.6.3
BuildVersion:  22G436

We found this out while experimenting with the VisionKit on Ventura. Another snippet that presents the same problem is: #592 (comment)

@nik012003 nik012003 added the bug Something isn't working label Feb 11, 2024
@nik012003 nik012003 changed the title Terminating event loop causes process termination in Sonoma Stopping event loop causes process termination in Sonoma Feb 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant