by microcolonel · 10y ago · 0 comments
I see some pretty glaring reasons why Python has not taken off in writing GUIs, especially on mobile.
1. The Python runtime is not very easy to embed on iOS and Android, and the sheer number of bindings needed to make it worth doing is immense.
2. Python's runtime is completely and utterly incapable of threading. Threading being almost essential to any decent user interface, this whole idea falls flat.
3. If the other two problems weren't enough, Python's single-threaded performance is really not great either. On resource-constrained systems (think phones) this hits doubly hard.
This is just plain wrong and the fact that many GUI programs are written in Python (dropbox, NetworkManager, Zim desktop wiki, etc) should be evidence of that. In fact, most people don't even realize these are written in Python. Yes, Python has the GIL. No, that does not mean it can't do multithreading. It merely means it can't do parallel processing on multiple cores with just threading. But that is by no means a requirement for multithreading, especially regarding GUIs.
This simply isn't true. Python has the GIL, but that doesn't stop it from making use of threads for IO or CPU bound tasks that release the GIL (using extension modules). There are lots of libraries for multi-threaded IO in Python (e.g., gevent, Twisted, Tornado, asyncio), and, not surprisingly, they are very widely used for web programming.
While you're AFAIK correct about running Python on mobile devices, and I think anyone will admit that Python's performance has never been great, one can have a great UI without threads: use coroutines and channels instead.
Fortunately, Python does have coroutines, and a channel library can be built in the fashion of Lua's channel library (https://github.com/majek/lua-channels). I don't know if anyone has done it yet, I'll grant, but a cursory look suggests that it's possible.
The basic idea is that one would spawn a coroutine to handle each UI element, and the coroutines would send messages to one another on channels. I've no idea how fast it would be (at a guess: terrible), but it should work.
With regards to performance, I found that one can produce very fast routines through use of specialized libraries for specific tasks, such as numpy etc. There are also great visualization tools, such as pyqtgraph which are blazing fast, at least, in my view, compared to any web interface. I have been skeptical about the html/js interface so far, because I am concerned with how fast large amounts of data can be surfaced from Python data models to HTML plots.
That said, I share the Python UI pain :/ As of now, I am stuck with QT and cx_freeze for desktop app development and the whole thing feels very medieval. The QT library in itself is great but at the same time it does not feel very "python". cx_freeze requires constant tinkering and makes debugging very hard at times.
What do HN users use for building GUIs for Python? :)
The only platform where Python could flourish without effort was Maemo, and for the very brief time that project lived, it did exactly that.