-
Notifications
You must be signed in to change notification settings - Fork 23
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
import numpy asynchronously causes EXC_BAD_ACCESS #85
Comments
Are you able to provide the code to reproduce? |
Sure, are the files for the simplest example:
The flutter code is a default boilerplate app, with the following update:
The |
I haven't verified yet, but just a quick though...Flutter on Apple ARM should generate a fat binary with both |
I don't think so, as it works perfectly (I can call numpy functions from python) with |
Will be looking into that - it should be a solution to that. |
Following, having same issue with my m1 max MacBook pro. |
Here's the source of this issue: python/cpython#96650 Setting import os
os.environ["OPENBLAS_NUM_THREADS"] = "1"
import numpy as np
if __name__ == "__main__":
print("Random:", np.random.rand()) Another workaround that proves there is something with threads - importing from threading import Thread
def test_numpy():
import numpy as np
print(np.random.rand())
if __name__ == "__main__":
thread = Thread(target=test_numpy)
thread.start()
thread.join()
print("Finished") |
Upon further investigation setting explicit stack size for a new thread in Swift fixes numpy issue as well. Default stack size for a new thread on macOS is 512 KB (524,288 bytes). Setting it to 1 MB does not cause the crash: let t = Thread(target: self, selector: #selector(runPythonFile), object: appPath)
t.stackSize = 1 * 1024 * 1024 // 1 MB
t.start() It could be a better solution for serious_python/Flet going forward rather than setting |
Amazing debugging! What do you think an optimal stack size should be? To avoid future issues I would propose to set it to 8MB, which is the stack size of the main thread on macOS. I think this is reasonable, as the function of that thread is basically that of a main thread. Edit: I checked and it works for me too! |
iOS has 1 MB main stack and 512 KB for secondary (source). Will do a parameter! 😏 |
Hello,
the package is amazing, but I encountered an error that makes it impossible to continue developing.
I am working on macOS with an Apple Silicon processor (M2).
The line
import numpy as np
always makes the code (and the whole flutter app) crashes with EXC_BAD_ACCESS, specifically, I tracked down the error to the linelet result = PyRun_SimpleFileEx(file, appPath, 1)
inSeriousPythonPlugin.swift
.The interesting thing is that if I use
sync: true
, the python code gets executed correctly without issues, but the flutter app hangs, so it's not a viable solution.I've tried using Isolates, but either the method channel cannot be invoked, or the flutter UI hangs (if I use
BackgroundIsolateBinaryMessenger.ensureInitialized
).Let me know if I can provide more info.
The text was updated successfully, but these errors were encountered: