-
Notifications
You must be signed in to change notification settings - Fork 47
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
Cannot initialize block support #218
Comments
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren). I haven't seen this error before, and PyObjC error message ("Cannot initialise block support") is an error that shouldn't happen. For some reason adding a PyObjC method to the Objective-C class for blocks doesn't work. One thing to look into: is PyObjC loaded multiple times? Two possible reasons for this:
Unloading PyObjC's C extensions is not supported because PyObjC makes changes in the Objective-C runtime and those cannot be reverted. |
Original comment by WayneK (Bitbucket: WayneK, GitHub: WayneK). On the theory it is some kind of 'unittest' loader/importer issue I lucked on a workaround. Running the methods below inside and outside a virtual env, with two different Python3.x and with pip-9.0.1, setuptools-37.0.0, wheel-0.30.0 : 1 Homebrew
2 Python.org
Method 1 This works on both:
Method 2 This fails on both:
Methods 2 runs the same tests as method 1 but programatically launched in Note: Only when using method 2 and only with python 3.5 does the afore mentioned warning appear:
|
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren). I've tested this with an (oldish) python.org 3.5 install on macOS 10.12 and cannot reproduce the problem. I do get the ImportWarning, that's probably due to the discover command not honouring pth files (PyObjCTools is a namespace package, and pip therefore doesn't install an init.py file). The warning should be harmless, if otherwise you'd get ImportErrors later on due to not being able to load modules in the PyObjCTools package. This is pretty annoying, I don't know why you get an error and debugging is rather hard when I cannot reproduce the problem. |
Original comment by WayneK (Bitbucket: WayneK, GitHub: WayneK). Continuing with the hunch... whilst creating simpler Obviously simpler tests in a test suite that can reproducibly fail for all would be ideal. But how best to mitigate it? and where, in user code or pyobjc? Test Cases:#Test 1Fails (as expected, it's just a trimmed down version of the original setup.py):
Test 2Works (bare bone unittest discovery, I assume it to be functionally identical to running the command line
Test 3
Because of the 'self import' in test 1 the test suite has been moved to
|
Original comment by WayneK (Bitbucket: WayneK, GitHub: WayneK). I've create a bare bones test case which only references
To remove ambiguity: Environment: macos 10.12.6 Pythons tested with:
(homebrew)
(python.org) Name: pyobjc-core Name: pyobjc-framework-CoreBluetooth |
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren). Thanks for the barebones test case, I can now reproduce the issue (python.org 3.6.3 with pyobjc 4.0.1 on macOS 10.3.1) Now I just have to find the cause of this error... |
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren). What's pretty interesting is the following output of an instrumented build:
Note how there are two lines with "Ran ... tests in ... seconds", and two lines with "objc._objc module initializer called". And this points to the source of the problem:
This causes setuptools to perform "import setup", which runs setup.py again (hence the two tests runs). I guess the test runner/discoverer in setuptools cleans up sys.modules after (or before) a test run, which results in two imports of objc and the error message you got. There are two possible fixes to this problem:
The first option is IMHO the cleanest solution. |
Original comment by WayneK (Bitbucket: WayneK, GitHub: WayneK). A third option, as mentioned in one of my previous comments, would be to specify the folder instead, i.e. test_suite='tests' But I think all 3 of the options don't follow the principle of 'the path of least surprise' and how many as yet unknown, or knowable, other scenarios outside of this setuptools case need this kind of work around? IMHO using |
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren). This is not a bug in PyObjC, to make the cause of the error clearer, this is basically what happens:
The custom "test" command runs the setuptools command twice. This runs the testsuite twice, and causes the problem you can into. That causes problems because setuptools resets sys.modules after running tests (that is, saves a copy of sys.modules before running the testsuite and resets sys.modules to that copy afterwards). Because sys.modules is reset the second run of the test suite doesn't know that PyObjC (or any other module you use) is already loaded and tries to load them again and that results in problems. I could probably detect this, but avoiding the error you're getting makes the code base more complex for an obscure error. I'm about to commit a changeset that improves the error message, but that's all I'll do. P.S. Note that your current setup.py file runs the entire testsuite twice |
Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren). Issue #218: Explicitly raise ImportError when trying to reload objc._objc Without this changeset reloading causes an exception about not being able Fixes #218 |
Original report by WayneK (Bitbucket: WayneK, GitHub: WayneK).
I will create a simple test case if needed, but I wondered if anyone had seen these before and might have any clues as to how I can fix them?
For now I only have the output from something a bit more involved, which is using CoreBlutooth on a background thread using the 'dispatch' workaround (Issue #215)
on this branch: https://github.com/TheCellule/python-bleson/tree/ci_tweaks
The errors below don't appear when I run the code standalone as a 'normal' script.
But, when run as a single test or test suite via 'python3 setup.py test' I see:
For a single test:
For a test suite where multiple tests run (but not concurrently) in the same process (probably the key there):
The text was updated successfully, but these errors were encountered: