News for hackers. Stuff that matters.
Re:PyParallel: How we removed the GIL and exploited all cores by jnbiche on Saturday June 07, 2014 @12:35PM (#7862415)
I'm really glad to see some of the Python committers taking a serious look at the GIL. Python is either posed for great victory (given its rapid rate of adoption in academia) or slow failure (given the rapid rate at which server apps are starting to migrate from Python to Go).

However, between accomplishments like Micropython (huge potential for Python on mobile/resource constrained devices) , PyPy's slow but steady gains, and projects like this, it's at least an interesting time for Pythonistas.

Now, if we could only get an optional static type checker... (heresy, I know). Dynamic typing is great for quick prototyping, and I would never want to lose that in Python, but I'm very uneasy now taking on any large projects or long-term projects without static typing. Mypy holds some promise here, but I think it will take sponsorship from a big company to push something like this to a mature state.

Re:PyParallel: How we removed the GIL and exploited all cores by masklinn on Saturday June 07, 2014 @03:13PM (#7862795)
> I'm really glad to see some of the Python committers taking a serious look at the GIL.

People have been taking serious looks at the GIL for a long time (there were technically working GIL-less versions of 1.5). The issue has never been that no one wanted to work on it (let alone that it was impossible), but that so far the single-threaded performance hit has been too large to be acceptable to the core team.

> Now, if we could only get an optional static type checker... (heresy, I know).

Er… how would that be heretic when Python 3's annotations were introduced to support exactly this?

Re:PyParallel: How we removed the GIL and exploited all cores by jnbiche on Saturday June 07, 2014 @04:57PM (#7863085)
>Er… how would that be heretic when Python 3's annotations were introduced to support exactly this?

I know well about Python 3 annotations, since that's what gave me hope to begin with. But I had the impression that every serious proposal I've seen on the Python Dev mailing list to integrate a static type checker in CPython had been met with rejection.

However, I just checked the archives and see now I was wrong. There have been multiple discussions about this, and even a working group.

GvR has given static types in Python the cold shoulder, but that attitude is clearly not shared by everyone in the community.

Glad to have been wrong in this case.

Re:PyParallel: How we removed the GIL and exploited all cores by maximilian on Sunday June 08, 2014 @05:21AM (#7864309)
There is also the mypy project (http://mypy-lang.org/). They are working on a type-checked variant of python. Currently it's just a pre-processing stage, but they eventually want to make it possible to AOT compile using the type information to get a faster language.
Re:PyParallel: How we removed the GIL and exploited all cores by freyrs3 on Sunday June 08, 2014 @12:11PM (#7865016)
It was originally part of the authors PhD work, it hasn't been touched since he graduated.
Re:PyParallel: How we removed the GIL and exploited all cores by unethical_ban on Saturday June 07, 2014 @01:03PM (#7862485)
I wrote a small XML parsing library for a firewall API recently. Just writing about 15 functions handing data off to each other made me nervous about not enforcing types. The best I could do was write function signatures and descriptions.
Re:PyParallel: How we removed the GIL and exploited all cores by calpaterson on Saturday June 07, 2014 @01:19PM (#7862523)
Types are not the only way to ensure correctness (and they aren't even the only thing you should use, even when they're available) - did you consider using tests?
Re:PyParallel: How we removed the GIL and exploited all cores by claudius on Saturday June 07, 2014 @03:33PM (#7862856)
Tests are not the only way to ensure correctness (and they aren’t even the only thing you should use, even when they’re mandated by policy) – did you consider using strong types encoding exactly the assumptions you spot-check with tests?
Re:PyParallel: How we removed the GIL and exploited all cores by klibertp on Saturday June 07, 2014 @07:43PM (#7863474)
> did you consider using strong types encoding exactly the assumptions you spot-check with tests?

Good luck encoding this simple contract (in Racket) exactly in your type system:

    (define/contract (fun numbers) 
        (-> (listof (and/c (integer-in 0 255) 
                            even?)) 
             any)
     ;; do something with a list of even integers in a given range
     null)
I hope you like your Zero and Succ n and are proficient with Agda or ATS or something like this.
Re:PyParallel: How we removed the GIL and exploited all cores by Shish2k on Saturday June 07, 2014 @08:14PM (#7863545)
I have no idea what you just said. Given that we're talking about type checking in python, care to give an example of a weakness of type checking in python?
Re:PyParallel: How we removed the GIL and exploited all cores by klibertp on Saturday June 07, 2014 @08:26PM (#7863567)
We're even, because I don't know about what "weakness" you're talking and why the heck you're bringing Python into abstract discussion on static typing.

Basically, my parent said that static typing can express many things that testing (which is not static, because it runs the code) can. This is true, but there are things you can't express in any of the commonly used[1] static type systems and I just gave an example of such thing.

Other than this there's nothing wrong with static typing in general and I'd be happy if Python got some kind of (optional) static type system, maybe in the vein of Typed Clojure and Typed Racket or Erlang's Dialyzer. Still, static type systems are not silver bullets and have their drawbacks - and that's all I wanted to convey in my comment.

Edit: [1] the type system feature which would let you encode the example contract I posted is called "dependent typing" and is available only in a very few languages.

Re:PyParallel: How we removed the GIL and exploited all cores by marcosdumay on Saturday June 07, 2014 @10:38PM (#7863812)
Pycontracts does that.

Racket is more powerful, but that is a bad example.

Re:PyParallel: How we removed the GIL and exploited all cores by klibertp on Sunday June 08, 2014 @09:21AM (#7864596)
This is an example of a thing you can't encode in (most) static type systems, not something that can't be done in Python! On the contrary, it is very much possible to do in Python thanks to its dynamicity...

I really don't understand what's going on in this thread; I'm stating an obvious fact that you can't encode things like "is even" in a static type systems without dependent types and that this is a drawback of such systems and I get downvoted. I never complained about my downvotes before, but this time I seriously don't understand what's happening. Did I fail that miserably in an effort to explain my position, or is this position controversial?

For the record, I replied to this:

> [dynamic in nature] Tests are not the only way to ensure correctness (and they aren't even the only thing you should use, even when they’re mandated by policy) – did you consider using strong [static?] types encoding exactly the assumptions you spot-check with tests?

With an example of dynamic test (a contract) which you'd have a problem expressing in any but the most advanced type systems.

Did claudius mean strong, but dynamic typing and I misunderstood? But then there is no difference at all between ensuring something in unit tests and in a type system as they are both executed at runtime.

I honestly have no idea and I really would like to know which part of what I wrote deserved downvotes to avoid writing such things in the future if for no other reason.

Re:PyParallel: How we removed the GIL and exploited all cores by marcosdumay on Sunday June 08, 2014 @11:05AM (#7864828)
There are some people around here that think a downvote is the appropriate answer to a post they disagree with, what's very unfortunate.

Looks like I misunderstood you, that's why my reply does not make much sense. But it is possible to verify such kind of constraints statically if you accept a certain amount of false errors, what all static type systems generate, to varying degrees.

Your example and the equivalent pycontract are static types that miss a static time verifier, not dynamic ones (pycontracts can only create static types AFAIK).

Re:PyParallel: How we removed the GIL and exploited all cores by coldtea on Saturday June 07, 2014 @04:28PM (#7863005)
Yes, hate them. Gimme types.
Re:PyParallel: How we removed the GIL and exploited all cores by pyre on Saturday June 07, 2014 @10:13PM (#7863763)
You hate tests, therefore want static-typing. You do realize that static-typing doesn't mean error-free code, right? Even with static-typing, it's probably a good idea to have tests.
Re:PyParallel: How we removed the GIL and exploited all cores by coldtea on Saturday June 07, 2014 @11:58PM (#7863933)
>You hate tests, therefore want static-typing. You do realize that static-typing doesn't mean error-free code, right?

As much as you realize that having tests also doesn't mean error-free code.

>Even with static-typing, it's probably a good idea to have tests.

For much less stuff. With a proper compiler, half of the kind of tests people do in Ruby land are totally needless. You can refactor and you know from the first recompile what has broken and where.

Re:PyParallel: How we removed the GIL and exploited all cores by ak217 on Saturday June 07, 2014 @01:29PM (#7862542)
There are a lot of ideas out there on how to do optional runtime type checking in a Pythonic way. My contribution is ensure (https://github.com/kislyuk/ensure), for example check out the ensure_annotations decorator (https://ensure.readthedocs.org/en/latest/#ensure.ensure_anno...).
Re:PyParallel: How we removed the GIL and exploited all cores by RodericDay on Saturday June 07, 2014 @03:21PM (#7862822)
I kinda wish I could keep all the type definitions in a separate file, myself. Like a map of the project.

That would probably make it easier to decouple from "Normal" python code too.

I'm not a very senior software dev or anything, but I imagine myself liking having my well-written, compact .py file detailing logic, and a separate 'doc'(?) file containing long-winded explanations of what some key functions do, and listing all the type consistencies I absolutely wish to guarantee.

Re:PyParallel: How we removed the GIL and exploited all cores by ak217 on Saturday June 07, 2014 @04:54PM (#7863072)
Have you used Sphinx for documenting your project? (You can also use RtD - for example, https://ensure.readthedocs.org/ has the docs for the project linked above). Sphinx makes it fairly straightforward to inline documentation and code while maintaining highly readable docs. Also, you can collapse and otherwise manage doctrings in IDEs like PyCharm.

So, if I were to implement what you said, I'd go with a file containing interface classes, i.e. classes that have getters/setters and type checking built in and documented, and another file defining logic operating on them.

Another pattern is to use something like:

    class Widget(object):
        ... define key constraints...
    """
    Long-winded docstring about do_stuff
    """
    from .impl import do_stuff
So all the implementation complexity of do_stuff is hidden in .impl (which also avoids stray exports).
Re:PyParallel: How we removed the GIL and exploited all cores by jnbiche on Saturday June 07, 2014 @05:02PM (#7863092)
>I kinda wish I could keep all the type definitions in a separate file, myself. Like a map of the project.

In fact, this is exactly what OCaml does (or can do)[0]. The interface file is not always required, but people usually include it for clarity, to make sure the compiler's type inference works according to their wishes, or to limit visibility of certain types and functions.

0. http://stackoverflow.com/a/3268836

Re:PyParallel: How we removed the GIL and exploited all cores by hcarvalhoalves on Saturday June 07, 2014 @06:04PM (#7863250)
> (given the rapid rate at which server apps are starting to migrate from Python to Go).

Do you have data for this claim or is it a hunch? I've seen this meme repeated a lot in HN.

Re:PyParallel: How we removed the GIL and exploited all cores by jnbiche on Saturday June 07, 2014 @07:47PM (#7863485)
Thank you for not asking in a rude and confrontational manner.

No, I don't have any solid data, but I do think the majority of people posting about Go on HN have either Python or Ruby backgrounds. I 've also found a lot of Python people in the Rust community (which I personally prefer vastly to Go).

People need more performance, particularly multicore performance. Traditional Python supporters can put their head in the sand about this if they want, but these highly-performant new languages have clearly found a niche among Python folks tired of trying to optimize all the time.

And yes, there's a fine line between conducting needed optimizations and wasting time prematurely optimizing, but people would clearly rather spend a little more time up front in exchange for a big speedup. The choice is no longer between C and Python -- there's a nice middle ground.

Re:PyParallel: How we removed the GIL and exploited all cores by hcarvalhoalves on Saturday June 07, 2014 @08:38PM (#7863590)
> No, I don't have any solid data, but I do think the majority of people posting about Go on HN have either Python or Ruby backgrounds.

Right. I find it odd because I don't get why Go is a supposed replacement for Python. Does Go have a framework like Django, a good SQL API/ORM, numerical computing packages, scientific packages, machine learning? This is where I see people using Python the most.

> And yes, there's a fine line between conducting needed optimizations and wasting time prematurely optimizing, but people would clearly rather spend a little more time up front in exchange for a big speedup

Yeah, fast by default is not only acceptable but desirable, I don't think using a modern compiled language counts as premature optimization. It doesn't look like using Go is a lot more complex/time consuming than Python, you lose some flexibility but win others (e.g., being able to distribute binaries).

Re:PyParallel: How we removed the GIL and exploited all cores by vertex-four on Sunday June 08, 2014 @08:39AM (#7864526)
Go is vaguely Pythonic (extensive stdlib, and generally adheres to the Zen of Python). Even if there's not much in terms of frameworks, it's great for replacing small parts of a server that have to handle a lot of load. A lot of people have existing Python servers that grew into being performance hotspots. It fits into the sort of niche that node.js does.

Personally, I'm not keen on it - I find that roughly 2/3rds of my code end up being error handling - and hope Rust eventually takes off.

Re:PyParallel: How we removed the GIL and exploited all cores by trentnelson on Saturday June 07, 2014 @07:58PM (#7863508)
> People need more performance, particularly multicore performance. Traditional Python supporters can put their head in the sand about this if they want, but these highly-performant new languages have clearly found a niche among Python folks tired of trying to optimize all the time.

I agree, the status-quo isn't great at the moment if you want to use Python and optimally exploit all your cores. I actually cover that in a more recent presentation: https://speakerdeck.com/trent/parallelism-and-concurrency-wi...

Re:PyParallel: How we removed the GIL and exploited all cores by zo1 on Saturday June 07, 2014 @07:02PM (#7863381)
It's a case of "keep repeating it and maybe it'll be true, someday, err, I hope". It's something you often see when people make mental investments into certain paths/things/ideas. And then they have to keep repeating it, both in order to try make it true, and to shield themselves from reality. Sort of like node.js
Re:PyParallel: How we removed the GIL and exploited all cores by jnbiche on Saturday June 07, 2014 @07:40PM (#7863467)
Wow, that's so full of wrong assertions and ad hominem I don't even know where to start.

First of all, I don't even particularly like Golang as a language, so you're incredibly wrong about my motivations.

Secondly, if you don't think Python to Golang adoption is on the rise among SV start-ups, you're living in a bubble. Look up HN Golang posts and count how many of them are from Python backgrounds. This may not represent the entire global Python programming community, but it's without doubt an important and influential segment of it.

Finally, I clearly struck some kind of nerve, since my comment is at the top of the page. You may not like my opinion, but it's evidently a common one.

Re:PyParallel: How we removed the GIL and exploited all cores by Shish2k on Saturday June 07, 2014 @08:18PM (#7863552)
In my sample size of one, I've been using python for new projects almost exclusively for a few years (still maintaining a bunch of other legacy code) - but now in cases where Go is suitable (things where I don't need Python's enormous and well-versioned third party library ecosystem) I've been switching to it. In general, it feels like Python and C had a baby and it inherited the best of both, so I can see myself pushing for it a lot more in future.
Re:PyParallel: How we removed the GIL and exploited all cores by meowface on Sunday June 08, 2014 @12:26AM (#7863968)
Personally I don't see why someone would switch from Python to Go. Go feels like a major step down from Python, in everything except for speed and parallelism.
Re:PyParallel: How we removed the GIL and exploited all cores by runeks on Sunday June 08, 2014 @04:13AM (#7864250)
Well then the reason for someone switching would probably be to gain speed and parallelism. :) I also think static typing is a big reason, for large projects at least.
Re:PyParallel: How we removed the GIL and exploited all cores by Glide on Saturday June 07, 2014 @01:28PM (#7862541)
That's not really heresy considering the existence of Typescript. You're probably right about it needing sponsorship from a big company. Adding type checking to a language is difficult enough, but the tooling around it is what really makes it powerful.
Re:PyParallel: How we removed the GIL and exploited all cores by jnbiche on Saturday June 07, 2014 @02:32PM (#7862681)
Yeah, Typescript is great. But by heresy I meant that's the concept is pretty rejected among many (most?) core Python developers, not that it's not feasible.

And I agree that the tooling is part of what makes static types so powerful, but I actually think the tooling might emerge organically if there's a well-designed, effective, and open-source static type checker available.

Re:PyParallel: How we removed the GIL and exploited all cores by Demiurge on Sunday June 08, 2014 @12:33AM (#7863979)
>I'm really glad to see some of the Python committers taking a serious look at the GIL. Python is either posed for great victory (given its rapid rate of adoption in academia) or slow failure (given the rapid rate at which server apps are starting to migrate from Python to Go)

Or neither, given that it's okey to have specialized tools for different jobs. Speed/networking was never supposed to be Pythons moto.

Re:PyParallel: How we removed the GIL and exploited all cores by urza on Saturday June 07, 2014 @05:35PM (#7863174)
If you like static typing and dynamic features, take a look at C# .. it has features inspired from dynamic and functional languages. Plus excellent support for parallelism and concurrency. Gone are times when C# was only object oriented java alternative.