- Podcasts
- Python Bytes
- #209 JITing Python with .NET, no irons in sight
#209 JITing Python with .NET, no irons in sight
Python Bytes
- November 27, 2020
- 33 min
- Episode 209
About this episodeTopics covered in this episode: Running Python on .NET 5 PEP 621 -- Storing project metadata in pyproject.toml GitHub revamps copyright…
- Running Python on .NET 5
- PEP 621 -- Storing project metadata in pyproject.toml
- GitHub revamps copyright takedown policy after restoring YouTube-dl
- Install & Configure MongoDB on the Raspberry Pi
- Extra! extra! extra!, hear all about it!
- A Python driven AI Stylist Inspired by Social Media
- Extras
- Joke
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#209 JITing Python with .NET, no irons in sight
But I kind of want to take a step back in my whole career and start back where I spent a little bit of time in .NET. Isn't that a weird thing for me to do on a Python podcast? Yeah, but you're kind of a .NET kind of guy in your past. I like C#, all right. Like if I wasn't doing Python, that's probably what I would be doing.
But look. Well, thank God for Python. Yes, I know. Well, also, I just want to point out, this is not my fault. This is Anthony Shaw's fault. Oh, okay. Yeah. So, Anthony Shaw wrote an article showing you how to use one of the more exciting inventions, evolution, something like that, with regard to Python and how it's actually executed.
And it has to do with .NET. So, he wrote an article called Running Python on .NET 5. So, there's a couple of layers we got to unpack here to finally put this together for everyone. So, way back on episode 49, like when I was living in Germany type way back, I talked about this thing called Pigeon, P-Y-J-I-O-N with Brett Cannon.
Okay. So, what this was is a way to like shim into CPython, something that would intercept when a frame, a function frame was being executed and, you know, hand over the Python bytecode. When you run Python, it gets compiled to those P-Y-C files into bytecode. But then, unlike, say, .NET and Java, which compiles that to machine instruction, it just jams that through the big C eval.c loop, like the 3,000 line switch statement.
That is Python's runtime, right? So, it gets like mixed into that workflow and it can actually take that. And there was talk about maybe compiling to the JavaScript Chromium engine, potentially, or to .NET, right? Those are like, it could be, so the idea was you could plug in some alternative JIT compiler to be given segments of Python and said, run this block of Python.
Cool, right? Okay. So, you know, obviously, compiled code has at least the potential to be a lot faster if it really understands what it's compiling than interpreted code. Okay. So, that's thing one. Thing two is .NET traditionally used to be this thing that ran on Windows and it only ran on Windows.
And that was a problem for a lot of people. So, Microsoft came up with this thing called .NET Core, which was the open source version, a multi-platform open source version of .NET. And just recently, they said, it's really silly to have these two things. So, let's just come up with this thing called .NET 5 that is the new cross-platform open source replacement that puts those things together.
Okay? Okay. And I'm leaking to like some of the announcements. They just did a conference over there. People can check it out if they want to go deep. Number three, things that run in .NET often are faster than Python. Like, you can debate that. But like, especially the numerical types of bits because they work with, you know, integers and floats, not PyObject long pointers and so on.
And I think that's a really interesting conversation because developing it is faster. If you bring in things like NumPy, all of a sudden you're down to C++, which is probably flat out faster. And there's just all these variations, right? Yeah. So, not to put too much of a point on it, but it is a place where code runs pretty quickly.
Pigeon is this project that allows you to plug a JIT compiler into the Python execution. So, the people over at Microsoft, Brett Cannon and Dino Veland, hopefully I got that right, the people involved, have been actually working on this for the last four years. And they're now, you can now use this Pigeon project in Python 3.9.
And the reason is, back in 3.7, there was a PEP called PEP523, which was basically an API for swapping out frame execution with a replacement implementation. And that's where you might take out Interpreter and inject JIT compiler. So, basically, they've just, you know, now that 3.7 came out with that, they've been building on that.
Yeah? Right? Because so we've got things like PyPy, but it's like 94% or whatever, like some, you know, mostly, mostly Python, but it's not all Python, right? So, this is really cool that they've got this high-performance runtime cross-platform JIT compiler that they just seem to have successfully plugged into Python.
Yeah. So, it's running which version of Python? 3.9. Oh, okay. That's awesome. Yeah. So, it doesn't like, like a lot of these other things said, well, let's replace the Python runtime with X and then it'll be mostly the same. And so, what this does instead is it plugs in just at that PEP 5.2.3 frame execution layer and says, you want to run this part of a function.
How do you do that? It's just that little bit that changes. So, other than that, it's the same old Python 3.9 that you know and love that I'm, as far as I can tell. Yeah. So, that's pretty awesome. Yeah. I'm pretty excited. It is pretty awesome. And then a little, like some extra news on this, unless you already mentioned it.
This happened a couple days ago. Pigeon is unfortunately frozen in the Microsoft repo, but Anthony's fork is now the official fork. What? Yeah. He's doing so much interesting low-level stuff, Anthony is. Yeah. He's got his, like, CPython source code book and, yeah, so, yeah, that's cool you're linking over to it.
So, all this stuff is very exciting and it has the possibility for code to run much faster. So, for example, given something that it can tell is here's a pi long object pointer thing. Could we convert that? And it's small. Could we convert that to just a, you know, four byte integer and do integer math instead of, like, complex math, right?
Like, that would make a tremendous difference in speed. Yeah. That said, what they've done here so far is just let's make it run and not break. Yeah. And now they're going to start working on the optimization. So, this JIT compiler hasn't done any optimizations yet, but they're going to start teaching Pigeon how to understand the Python code.
Say, could we restructure that to get the same outcome, but in a much more native to the machine way? So, is it faster? A little bit. Not a ton yet. But it opens the door for huge improvements by working specifically on the JIT compiler, understanding how to take code that it gets and turn it into something.
Yeah. And this sort of cross work and stuff is interesting. Just interesting about, you know, working with languages, working with whether or not you're going to do interpreted versus JIT compiled and things like that. It's a very interesting story. Yeah. Yeah. And that Stack Overflow thing I linked to, they also talk about PyPy, PYPy, and how it also made the example there go quite a bit faster.
So, anyway, JIT seemed to be an interesting option here. So, from PEP 523 to 621, let's keep rolling on the PEP, man. The PEP 621 is, I guess, trying to standardize some of the metadata in PyProject.toml. So, we've talked about packaging in PyProject.toml a lot, I think. The different projects like Black and Flit and others have been using a loophole in the original spec that said, yeah, you can put extra stuff in there, but we don't recommend it to everybody who's putting extra stuff in it.
Like, but are we forbidden? No, let's do it. No, yeah. So, they took out the recommendation to not do that. But there's motivation to sort of standardize on the things that are building packages and building wheels. It'd be really great if, like, we could kind of standardize on what is in there and what names.
The big players are set up tools and poetry and Flit, of course. But there's others around that do this. And this PEP actually includes the authors of all of those in trying to get some of this together. Some of the motivation is to try to have some of the metadata statically defined so that other tools can read it quickly.
And we can build an ecosystem around just a standard set of things. That makes a lot of sense. If you're going to put it there anyway, make it at least interchangeable and useful. Yeah, and just kind of define what it means to have these things in there. And one of the nice things I looked for because it kind of bugged me about the old packaging was whether or not email was required.
And it's nice to see that both name and, I mean, usually you should put, like, an author or maintainer name. And email is encouraged, but I don't want to put my email in there. And it's optional, so that's cool. Yeah, exactly, because then it gets published up IPI. And, man, anytime you put your email on the internet, you just get communication.
This is still in draft form officially, I think, but I think it'll go forward. It doesn't change any of the existing core metadata, and it doesn't attempt to standardize all things that you could put in there. But some of the common things like name, version, description, where the readme is, which Python version is required, what license you have.
Yeah. I'm actually surprised. I'm like, well, we haven't already standardized this stuff. Exactly. You know what else is reasonable? Is learning pytest. Yeah. That's a pretty reasonable thing. And often people do it with a book? They do. And I'm still getting some really great quotes from people, which would have been good for me to be ready with that.
I'm about to release a FastAPI course. It may actually be out by the time people hear this because there's this time travel thing that we do with podcasting. Not that much, but a little bit. So people should definitely check that out over at Talk Python Training. And I've already started writing the next course.
So that'll be fun. Big secret there. You're cranking them out. I'm really liking this stuff. And I'm really looking forward to the FastAPI course. Yeah. Thanks. It's all done, recorded. It just needs the final editing set on the videos. And it's going to be really fun. I think people will love that framework.
I had a lot of fun exploring it. Cool. You know what's not a lot of fun? When you get a DMCA complaint from the Record Industry Association of America to take down your GitHub project. What? That happens? Apparently. It happens to me all the time on a really funny story. I did a webcast years ago when I first moved to Oregon.
And there were some people who had dialed in. And it was so frustrating. Like there's all these hundreds of people. Somebody put the call on hold because they had someone come in their office. It started playing like the hold music to the whole organization. Everyone, like all hundred people were hearing this hold music.
And we're like, how do we get rid of this one person without getting rid of the rest? It was really bad. But the reason I bring this up now is it was like a song, an actual copyrighted song. When I published the webcast to YouTube, it got taken down because the hold music that was interrupting the webcast got a DMCA complaint.
So anyway, these things are super frustrating. You're like, why? This makes no sense. Anyway, so here's the story. GitHub had taken down YouTube-DL. YouTube-DL, I believe it's a Python project that allows, basically gives you a CLI for downloading content off of YouTube. So if you're like, oh, that video is really awesome.
Therefore, we hate it. And so we asked GitHub to take it down and get up dead. Interesting. Yeah. But here's the news. They revamped their copyright takedown policy, put a bunch of other policies in place, set up a legal defense fund, and restored YouTube download. And gave the middle finger to RIAA, basically.
Yeah, because this tool, I mean, maybe this tool helps you do something you shouldn't, but it's not itself. Yeah, yeah. So also, you know, big shout out to the EFF, Electronic Frontier Foundation, in that they helped, like, critique and go through the actual legal bits of this and show GitHub, like, you know what?
Actually, their main complaint is actually not even what's happening. So the RIAA argued that the tool ran afoul of Section 1201 of U.S. copyright law by giving people the means to circumvent YouTube's DRM, digital rights management. So that's the important part, right? Like, it's breaking this encryption prevention of copying that YouTube has.
Only if the video is in an unprotected, like, MP4 format will it even work. So their main complaint that, oh, it breaks this DRM, it doesn't break DRM. So they said, we're putting it back. Okay. Yeah? And as part of this, there's, like, a pretty big uproar, I believe. So GitHub is implementing new policies to avoid the repeat of such a situation moving forward.
First, it says the team of technical and legal experts will manually evaluate every single section 1201 claim. That's cool. Yeah. And instead of just going, whoop, it goes down, they said if the company's team, technical and legal teams, ultimately find issues with the project, GitHub will give its owners a chance to address those problems before taking down their work.
That's nice. Yeah, that's cool. And GitHub is establishing a $1 million legal defense fund for developers if somebody sues them about their GitHub project. That's actually awesome. Yeah, this is a feel-good story, right? I think. Well, yeah, because the individual developers sometimes are just, like, you know, a handful of people or even just one person making some cool tool that they think is neat.
You're giving this stuff away. You can't get a lawyer or whatever to defend yourself. And a lot of times it's published through GitHub under your personal name, right? So, like, Talk Python has an organization, and we pay GitHub, like, 50, 60 bucks a month to have our organization maintain repos on there, right?
Apparently, I'm a subscriber to their newsletter. And they said they just launched a podcast miniseries called How to Fix the Internet that examines potential solutions to six ills facing the modern digital landscape. And this sounds like one of them. So, people are, like, really interested in this.
They can actually listen to the EFF series there. Yeah. Nice. Anyway, that's a wild story, right? It is very wild. Yeah. All right. What you got next here? Another one of my favorite topics? Yeah. So, you like MongoDB, right? I do. I love it. So, I was actually thinking the other day, how small of a machine could I put MongoDB on?
So, that's how he does it. He installs the Ubuntu server 64-bit on a Raspberry Pi, configures the Wi-Fi, installs MongoDB. But there's like a kind of a quirk on how you're supposed to install MongoDB on it. And then set up an account so that you can safely have a MongoDB server running in your house.
He recommends this is like a local network thing, not even a company-wide thing. Just if you're using it yourself, go for it. If you already have a Raspberry Pi and that's like your thing that is running, that is your sort of file server or whatever reason that you have it running for, and you want a database, it's cool that you can set this up here, right?
I mean, you probably wouldn't host like a professional website on it. But who knows? Maybe you would. I've got stories. One of the things I love about MongoDB is just the ease of like setting up storage areas for it and stuff. And you can just... Yeah. It's easy. You just talk to it like you expect it to be and it just becomes that way, right?
Definitely. If you've got like an IoT thing, smart home thing going on and you want to store it somewhere. Yeah. Yeah. Very cool. I love it. Nice. Good find there. So, this next one is like this new little section I've just invented just for this one time called Extra, Extra, Extra, Hear All About It.
Okay. Let's start with some listener feedback. So, remember I went on a rant, I'm known to do that sometimes, about the Stack Overflow Survey and how they were comparing things that were like simply not comparable? Yes. And one of the things I picked on was SQL. And I said it doesn't make any sense to have SQL compared to the popularity of SQL compared to the popularity of Python or the popularity of C#.
But if you ask them like, what kind of developer are you? They wouldn't say I'm a SQL developer. They would say I'm a Python developer or I'm a Java developer or .NET or whatever is not SQL, right? So, John Nickerson said, hey, I feel like you're saying that people just use SQL or not real developers.
And then one of them also adds to the other, but they're put together as if they're separate and being compared. And that just didn't feel right to me. Yeah. I mean, yeah, there's definitely people that specialize SQL queries. That's a cool thing. And there are people that do that as professionally.
And I think that's super cool. But like you said, having SQL being used by your Python is not the same as being a SQL developer. Right. JavaScript has exactly the same problem. Yeah. All the web developers that use any technology whatsoever, they also use JavaScript. But that doesn't mean Node.js is massively more popular than everything else.
Also, I just wanted to quickly follow up. When people fill out those surveys, they check anything that they've ever done. Yes. Exactly. Have I touched CSS this year? Yes, I'm a CSS developer. All right. Next of the extra, this is extra number two. So remember we talked a little while ago about Peter Van Rassen, creator Python, retiring.
We talked about him stepping down from the steering council and saying, I'm just going to chill for a while. Yeah. Yeah. He's done chilling. So actually the big news, I think this is pretty big news, is that he joined, maybe as a technical fellow. I'm not sure exactly what the official role is, but he joined Microsoft now.
That's pretty high up. That's awesome. Yeah. I think he should do call support. That'd be great. Yeah. So he said he decided to join. He said, I decided that retirement was boring and have joined developer division at Microsoft. To do what? Too many things to say, but it'll make using Python better for sure.
And not just on Windows. There's lots of open source here. Watch the space. And there are 5,000, no, 2,100 quoted tweets. And I'm not sure how to tell me how many conversations, but there's like an insane number of replies to it as well. And a bunch of familiar faces and listeners actually right there all replying to Guido.
I'd have to dig. I think I know where it is, but I know generally what part of the house it's in, but it's in boxes under boxes. Anyway, that's really interesting. Okay. That's two. So extra, extra, extra. If you think about popular editors in the Python space, really these days, it feels like it's narrowing down into VS Code and PyCharm.
Like it used to be just completely all over the map when I asked that question on Talk Python. And these days it's VS Code, PyCharm, VS Code, or I was on one and switched to the other. And Vim. Yeah. And Vim. They don't say something like that. It's either Vim or Emacs. Yeah. It's like one of those types.
Cool. Yeah. So anyway, they built this thing called Nova, which is like a reinterpretation of their interpretation of what a code developer editor should be. And it's got cool things like GitHub integration where it shows you, say, the issues around the code that you're working on and stuff like that as you're going through it.
It's got a Vim mode. I'll try it. I think it does. I'm pretty sure I remember it. All right. Last thing. Extra, extra, extra, extra. I installed Big Sur on my Mac and it didn't die. And all the Python things seem to be working. All the websites run. The MongoDB stuff's working. So that's really pretty neat.
Install MongoDB. Install a lot of things like that. Open SL. SSL. Seems always getting there somewhere. And also I said that I ordered a new MacBook Pro instead of the Apple Silicon thing. I actually canceled that and I'm getting a MacBook, a Mac mini, Apple one. Very exciting. I'll let you know how it goes.
It's really awesome. And the price is like. Okay. So I got like $1,500 back by canceling my MacBook order and a faster computer. Nice. So anyway, we'll follow up on that. Let's see how it goes. Anyway, that was extra, extra, extra, extra. You're all about it. Nice. Well, so normally my spot would be number 6, but that'd be like, what are we at?
Like 9 now or something? Yeah, we're at 9, yeah. Okay. So actually, this is a cool article. I love this story. Dale Markowitz wrote an article called, I'm masquerading it right now. But it's a Python-driven AI stylist inspired by social media. No way. So it looks at like Instagram and like influencers and stuff and says, this is how we think you should dress and look?
Yeah. So one of the cool ideas, and it's so cool. So she works for Google. So she's using a whole bunch of Google tools that are available to everybody else too. Things like Google Storage, Firebase, Cloud Vision API, Product Search API and stuff, which actually I've never played with any of these, but it's kind of neat that they're available to really anybody that they want.
And so the idea is she took pictures of all of her, every item in her closet. And then has like folders for containing the pictures of her related. So like, let's say if you've got a shirt or jacket, a few angles of the shirt, and then threw those in a directory and then did that for everything in her closet.
And then took influencers that she likes, like a couple of social media accounts that do fashion shots that she likes how they dress. And then throws AI at it and scripts the whole thing with Python. So this thing will tell her for this particular person that this look for this from this photo, you can kind of do this look if you use this shirt and those pants and these shoes.
I love this idea. It's pretty cool. Yeah. It's pretty. All right. Two thoughts. So one, I remember my statistics class, they talked about, well, if you have like three shirts and two pants and five socks and two pairs of shoes, how many, you know, here's the combinatorics of how many like combinations you might have.
Yeah. And also like she had to put it in place. One of the things she had to do is put in place like a score. So if you like, for instance, if you've got like multiple gray shirts, they all might fit picture with the gray shirt, but they, she made it so that there was scoring so that you'd get the, like the, you can pick the highest score outfit or something.
Yeah. There you go. Awesome. Yeah. But there's, there's some facial hairstyles that if we could get a tool that would tell people to not try certain facial hairstyles based on what they, their face shape is, that would be good. That would be very, I did see a guy who had like a super big beard and decided to cut it off.
Well, I already went off the, off the deep end on the extras. How about you? Yeah. Let's skip to the joke, man. Oh man. Sounds good to me. All right. So this is a little bit of back to the future, Marty McFly and doc, all that stuff. So, you know, he's got that cool DeLorean, that stainless steel DeLorean and it's got the flux capacitor.
But I technically have it installed. I get this big pop-up that has to update it about every three weeks. Like, there's an update for your computer. Click here to upgrade Edge. I'm like, I don't even run this thing. Why do I keep getting this? I know I get it. But like, why do I have to keep getting it, I guess?
You know, the internet is not an application. What? It's not? Awesome. Yeah. So, that's a pretty good little shoot to the future one. Yeah. So, link to that in the show notes. People want to check out the graphics. Well, thanks a lot. Yeah, you bet. Thanks for being here. And thanks to everyone for listening.
See y'all. Bye. Thank you for listening to Python Bytes. Follow the show on Twitter via at Python Bytes. That's Python Bytes as in B-Y-T-E-S. And get the full show notes at pythonbytes.fm. If you have a news item you want featured, just visit pythonbytes.fm and send it our way. We're always on the lookout for sharing something cool.
