6 ms·
Python's GIL implemented in pure Python
- ponco 8y agoReading the headline I couldn’t help but think “But why?”. Actually quite interesting and valuable implementation info if you’re ever doing threading with CPython.
- StavrosK 8y ago> Reading the headline I couldn’t help but think “But why?”. Reading the article will clarify.
- pests 8y agoReading the rest of the post you're replying to might help.
- angrygoat 8y agoYes, I think the headline would be better as "Python's GIL explained in Python code"
- linsomniac 8y agoWhen I first read about pypy a decade ago, I also asked myself "but why". Now it is one of the most interesting projects out there and any talk they give tends to be really worth listening to. Their talk on Software Transactional Memory blew my mind.
- MaxBarraclough 8y ago> Note that this code will not run if you will try to execute it, because it's missing bytecode execution logic. So much for "implemented". Incidentally, apparently PyPy has a GIL too[1], complete with a detailed description in a source-code comment, similar to the one quoted in the linked article[2]. It's written in C. Isn't the point of PyPy that it's written in a Python subset? [1]http://doc.pypy.org/en/latest/faq.html#does-pypy-have-a-gil-why http://doc.pypy.org/en/latest/faq.html#does-pypy-have-a-gil-... [2]https://bitbucket.org/pypy/pypy/src/00f8eae1/rpython/translator/c/src/thread_gil.c https://bitbucket.org/pypy/pypy/src/00f8eae1/rpython/transla...
- masklinn 8y ago> Isn't the point of PyPy that it's written in a Python subset? That subset is rpython (which beyond a python subset is a framework for implementing dynamic language runtimes: https://rpython.readthedocs.io/en/latest/ https://rpython.readthedocs.io/en/latest/). You'll note that the gil is part of rpython.
- StavrosK 8y ago> So much for "implemented". This comment reeks of middlebrow dismissal. The author implemented the GIL in pure Python for illustration purposes, as it says in the very first paragraph of the article, yet you complain it won't actually run. Where were you thinking of using a pure-Python GIL that this is such an inconvenience to you? > Isn't the point of PyPy that it's written in a Python subset? More dismissal. The point of PyPy is to be a JIT. What it's written in is incidental, not "the point".
- MaxBarraclough 8y agoMy first point was a bit of a nitpick, sure, but I'd never describe my work as 'implementing' something unless it actually worked, in full. As to my second point, you're reading dismissal where there is none intended. My question wasn't rhetorical. Ironically, you've just dismissed my question. Is Wikipedia's PyPy article mistaken in describing it as 'Written in RPython'? I'll go ahead and fix it if so, or perhaps I'm missing something about the status of the C code.
- StavrosK 8y agoWhat word would you use to describe writing something in a language for illustration purposes? PyPy is written in RPython. You posted a link to the RPython translator's source code.
- MaxBarraclough 8y ago> What word would you use to describe writing something in a language for illustration purposes? I'd probably go with "The GIL explained in Python". > PyPy is written in RPython. You posted a link to the RPython translator's source code. But RPython is a part of the PyPy project, no? Do you consider the Wikipedia listing to be accurate?
- saywatnow 8y agoThis is nice .. but it could be nicer with (pun intended) use of the context manager protocols, a few less empty lines and a bit of minor refactoring for readability. Is execution_loop really meant to start and end holding the GIL?
- dharmab 8y agoTwo empty lines before function definitions is part of the PEP8 style standard, which is widely used in the Python community. Most Python autoformatters and linters default to PEP8. As for empty lines within code, I personally find it helpful to visually separate logical segments.
- nomel 8y ago> As for empty lines within code, I personally find it helpful to visually separate logical segments. I see it as, if a function is like a paragraph, then the whitespace between lines deliminates sentences. I very much dislike run on sentences that are attempting to explain complex rules/topics in english and in code. Spatial grouping is very natural for the eyes and mind.