Bypassing the GIL.
In this topic I am going to be documenting my advantures trying to bypass the GIL using Apple's threading api and objc_utils. I also want to develop it into basically a multiprocessing API for pythonista.
Firstly some docs.
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Multithreading/Introduction/Introduction.html That is on just Multithreading.
I may end up using the Dispatch query.
Okay so far jaunt using NSThread will not help. As it still obeys the GIL.
what's your end goal? i.e what situation do you see benefitting from gil bypass? there are some specific ios background tools like for downloading files which hand over the downloading task to the os.
it seems to me that anything involving objc executing python code still trampolines code back into the interpreter, so won't help you. In the beta 3 you might have luck running a program in each interpreter -i'd assume each interpreter has a seperate GIL.
I am trying to get something like normal multiprocessing in Python. I was thinking reading could work with objc because I have had things from objc code I can before the script that still was running while a new script was running.
I think bypassing the GIL completely is not possible - after all, all the code you can write on Pythonista needs to be run by the Python interpreter. Even if you have multipe threads from Objective-C, to execute Python code a thread still needs to hold the GIL, which logically only one thread can do at a time.
You are probably right. but I can still try.
If the goal is to "run multiple programs at once", Threads work fine. For instance stash does this well (you can "background" commands using &, etc).
Certain things, like numpy calls, the gil is released while numpy is executing a c call (and numpy is linked with the Accelerate framework, so theoretically should be using multiple cores for certain types of operations).
Certain bits of the ui are just thin wrappers on objc, so most of the ui handling is done outside of python. You can run two or more ui's , and since mostly the ui is handling user interaction, and then calling back to python, using Threads or ui.delay, etc for long running tasks ensures that things stay responsive
Rather than try to figure out how to bypass the gil, which probably cannot be done in a generic way, focus on what you would do if you could.... their may be some native frameworks, etc that let you accomplish the same goals.