Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
This is episode 286, recorded May 31st, 2022.
I'm Michael Kennedy.
And I'm Brian Okken.
And this episode is brought to you by us.
If you're looking to learn Python, check out all the courses over at Talk Python Training.
If you want to get better with testing, check out Brian's pytest book, second edition.
Yes.
Yeah.
Yes, indeed.
Indeed.
All right.
Well, let's jump right into it, Brian.
Okay.
Tell me about the GIL.
I do want to talk about the gill, but I was just realizing that we're at 286.
I just started watching Big Bang Theory with my youngest kid.
And there's 279 episodes of them.
So we have more than it went on forever.
And we have more episodes than them.
That's quite the milestone.
I mean, you divide that by 52.
That's a lot of years.
We've been doing this for a while.
Yeah.
So Python and the GIL.
So the GIL is a thing, right?
It's like something everybody knows about.
I think people know about, but not too much.
So, I mean, you kind of, it means we can't do multiprocessing, but we can, but we can't.
So what is it?
And so I really like this article.
So this is an article called the Python GIL past, present, and future, because we have been talking about some of the no GIL options that are coming.
So this is really nice.
It's a, who is it?
Gary, Barry Warsaw and Pavel Polowicz, I think.
Anyway, really great article on the Backblaze blog.
And it starts out and goes through sort of what is the gill, why we have it.
It's a lot around the way in some of the history is around reference counting.
And maybe you knew that off the top of your head, but I forgot.
That reference counting is something, that's how we do memory management and all sorts of stuff within Python.
But to make it an easy implementation, there's this global interpreter lock.
And that just basically, instead of lock, like other code, you lock individual items, shared memory that you're using.
We just say the interpreter, let's just lock that and all of the variables that it uses.
It's not just reference counts, but other things too.
And this is just, it's a fairly quick read, but enough detail that you really kind of understand what's going on.
It does talk through, you know, reference counting, talks through that, some of the advantages, why it's really kind of handy to have it around.
But then attempts to remove it, including, like, I didn't know about this one.
There was a free threading one in 99.
From 1999.
Yeah, that's, I didn't know about that one.
It actually was successful.
It just made your Python code really slow.
So, not good.
And then Larry Hastings' galectomy, he's had a lot of PyCon talks, or a few PyCon talks around this.
So, that's an interesting thing to read about.
There's a little more, there's quite a few interesting bits in there.
But it never really got back into main Python.
But we're getting a little closer where, with this no-gil stuff.
So, there's no-gil stuff going on with Sam Gross.
From Sam Gross.
Yeah.
And then also, we've got Guido and others in Microsoft now working on this problem of speeding it up and everything.
So, really great discussion if you want to catch up on all the history of the GIL and where it's going.
And then a little prediction at the end of, we're going to see speed-ups.
Because of these efforts, we're going to see speed-ups in the next few years.
It's just going to get faster.
And then, if we get no-gil, it might be maybe five years from now.
Yeah.
It's pretty exciting.
There's some very neat work.
The stuff that Sam Gross is doing is quite interesting.
Yeah.
What's really cool is it's not just theory or people playing, right?
The Python 3.11 is a lot faster than the previous Pythons already.
And it doesn't even really touch the GIL side of things.
So, there's actual progress being made.
Yeah.
And it's actually, it's pretty exciting.
Pretty exciting time to be part of Python.
Like, it's never not been exciting, but, you know.
Yeah.
It only gets more exciting.
How's that?
Yeah.
So.
Hey, let me ask you a meta question.
So, this is on the Backblaze blog.
So, Backblaze.com is one of the, I think, better sort of backup my computer somewhere off-site
sort of things.
Yeah.
And the fact that they're blogging about the Python GIL is kind of interesting.
I wonder if they're a big Python shop and we just didn't know it.
Well, there's, like, I didn't know.
It's on their blog.
But, I mean, we've got Barry Warsaw in there.
It's written by Barry Warsaw and Powell.
Yeah.
So.
Are they, is he, he's, he says he's currently a senior engineer at LinkedIn.
So.
Yeah.
I'm not sure.
Sometimes life's confusing.
Yeah.
Not sure how this ended up there.
But, yeah.
No, but it's cool to see Backblaze supporting the Python world with some, some dives into the.
Yeah.
Maybe somebody from Backblaze can reach out to us and tell us what's going on.
Yeah.
That'd be great.
Also great.
Wouldn't it be cool, Brian, if we could take our Python program, whether this is a CLI or
some other app that we need to have for people to run.
And instead of saying, well, make sure you have this version of Python at least to make
sure you've set up a virtual environment, you've installed these things, and then you've got
this in the path, and then you've got this environment variable.
Now you can try to run our thing I gave you.
Yeah.
If you could just give them a single binary that contained all the Python, contained the
standard library, and you said you run this, and that's your app.
That's not bad, right?
Yeah.
So let me introduce you to PyOxy, the PyOxy Python runner.
Now, a while ago, we spoke about this thing called PyOxygen, no, PyOxidizer, that's what
it was, PyOxidizer.
And this is kind of like an advanced version of Py2.exe, or Py2.app, or PyInstaller.
But what's really nice is that it bundles the stuff up just sort of all into one thing, and
it runs out of memory instead of creating like a file structure of the files that you need,
and then, you know, sort of altering the path.
So like a copy of Python will run that, and so on.
So this PyOxy attempts to make the features of PyOxidizer more accessible and simpler for
people.
Okay.
So here's the deal.
It is an executable program for running Python interpreters.
So you can just give somebody this one PyOxy file, and they can, instead of saying Python
this, they can say PyOxy, some Python file, right?
You can say like run Python or run Python --and give it a file or something along
those lines, right?
And it's just a thing you copy around.
You don't have to worry about installing it or configuring your system or anything like
that.
So it's kind of a really easy way to pass around an executable that is Python and the standard
library without all the overhead or setup of actually installing a Python runtime.
Okay.
Wow.
Okay.
Yeah.
So let me go back up here.
That's pretty cool.
That's one.
It's a single file.
It's a single file that is a highly portable distribution of CPython.
So for example, on macOS and Linux, it statically links in a lot of the files that are dependencies
that you might find, you know, so if you try to run something in Python, it might go like,
oh, you have to install this other like C library in order for it to work correctly.
So all those things are also like its dependencies are statically compiled into it, which is pretty
cool.
Another thing that's interesting is it gives you a lot more control over the interpreter
and how it behaves.
Like you can pass it configuration files and do all sorts of crazy stuff to really tweak
the behavior of the runtime, the Python runtime that it comes with.
Yeah.
And it's just to sort of make PyOxidizer apps more accessible.
Okay.
So yeah, so it gives you, it's built with PyOxidizer and basically it gives you its own standalone
one.
Like I said, the, it has the whole interpreter.
It has the stuff statically linked.
It has the standard library.
And I think you can link your own libraries into it as well, which is pretty awesome.
And you could also give it, like I said, more control.
So you can create a configuration YAML file.
And when you run it, you can say, I want you to debug allocations, or I want you to, you
know, run, run this command to initialize the interpreter before it starts to run any code
and things like that.
So you can give it this YAML config file and so on.
So anyway, it's a pretty new project.
This is from Gregory Sork.
And he says, it's very young.
I hacked it together to try to get better exposure for PyOxidizer.
For people who want to build things that they can distribute more easily and so on.
And for me, he's talking about, oh, there's some certain circumstances where maybe you want
to have people run your script so you can send the script and then this thing and so on.
It's supposed to be sort of on par with zip app, which lets you ship the zipped up thing
of your app and then run it.
But the benefit is it already comes with Python.
Like a lot of these zip, shiv, pecs, et cetera.
They all require that Python is installed on the system.
And then you can run that, right?
With its dependencies.
But this is like, no, it even comes with Python.
So all that is pretty good.
What I would love to see out of this is, could I take this and build some sort of UI framework?
Here that, I don't know, maybe with PyScript and then get like a UI framework I can ship
to people and just go download this, double click it.
There's your app.
Who knows?
Yeah.
But anyway, if you're shipping Python to people, this might be worth checking out.
Yeah.
Neat.
Yeah.
Kim out in the audience asked, it looks very handy.
Does it make cross-platform executable?
I think you might have to run a build command or something or ship the right binary for each
platform.
But it does support macOS, Windows, and Linux.
So that's pretty cool.
Now, maybe you covered this and I just missed it.
What does it, does it deal with my dependencies?
Like if I have third-party dependencies?
That's what I'm not 100% sure how to do.
And I looked through it.
I was looking for that.
There's this oxidized importer.
Okay.
Which it talks about like this embeds a copy of the Python standard library and it imports
from memory using the oxidized importer.
I think that you could use that as well for your own dependencies.
And I'm pretty sure that's the goal of this pie oxidizer project in the first place.
So I would think so.
But nothing from this article was really clear.
Like, and here's how you bring in requests or HTTPX or whatever you're going to bring along,
you know?
Yeah.
Okay.
Or pie test.
I was actually just thinking if I, you know, run these tests.
Well, what version are you using?
Okay.
Just fine.
Here, just install this and run this test with this.
And that would be cool.
Yeah.
Exactly.
Yeah.
And Alvaro is, you know, when I was talking about UI stuff, he says, what about pie oxy
plus textual?
Yeah.
That'd be pretty neat as well.
Yeah.
Just around the corner.
Yeah.
Cool.
All right.
Well, that's pie oxy.
People can check it out.
All right.
Well, how about regular expressions?
Do you like those?
When they work, I love them.
When they don't, I'm like, what is this madness I've gotten myself into?
Okay.
So I was almost afraid to like talk about this, but it's a really awesome article because,
because sometimes you need regular expressions.
And, and one of the things there's lots of, I look that I like about this article.
What I'm talking about is an article called, the unreasonable effectiveness of f-strings
and verbose.
Um, so, regular expressions and all languages, including, I think, and including Python have,
um, have a notion of, verbose mode.
And I've always been enticed by this.
The verbose mode idea is that you can like, instead of having this reared, you, you still
have the hard to read, regular expression stuff, but you can put comment, you can put spaces
and comments in it.
And, and then it can be multi-line, right?
What?
It can be multi-line.
Yeah.
It can be multi-line and you can have a bunch of, comments in there to say, oh, this
part of the regular expression, what it's doing is this, you know, and then, so it
makes it little, little snippets of regular expression are easier to read.
You're like, oh yeah, I can see that it's doing that.
Great.
When it's, when you clog it all together, which makes it really hard to read.
So, and then, and then of course you can build up strings in Python with f-strings
and do string replacement.
How awesome.
So that's what this article is about is really talking about, using, taking some
of the complicated bits of your regular expression or duplicated bits where you, it shows up several
times in your regular expression and pulling that out, that string out, and even maybe commenting
that.
And then, dropping it in with, f-strings to build up a complex regular expression.
It's, it's brilliant.
It's brilliant.
And it also is one of the best explanations I've ever read on, on, on, verbose, regular expressions.
So it's pretty cool.
Yeah.
I never really thought to refactor the pattern so that you have multiple strings.
Yeah.
Be like, here's the part that's repeated.
So we'll have a pattern that that's that thing.
And then F string it into the other pieces.
Yeah.
Uh, but it makes perfect sense.
Of course you should do it.
Yeah.
And now, I mean, I don't use it.
I mean, actually I kind of do, I use regular expressions on a regular basis.
Um, but, the, but not like every day, but, but it's always something that I
whenever I put it in there, I'm like, is anybody else going to be able to read this?
And so I put comments around it, but I've never, I haven't ever really embraced verbose
mode and I'm definitely going to use this now.
Yeah, for sure.
So the, the other thing real quick is you can have f-strings and you can have raw strings
and you can have raw f-strings apparently in Python.
So the prefix is F R triple quote, multi line.
Like that's, that's some serious string action happening right there, man.
Yeah.
Um, raw f-strings.
Nice.
Yeah.
And, Neil out in the audience asks you, Brian, do you like your regular expressions?
Greedy or non greedy?
Okay.
I, I, it depends on what you're trying to do.
So.
Yeah.
I don't want mine to be greedy.
Let's share, share, share kindly.
All right.
Are we ready for the next one?
Yes.
Cool.
All right.
So this one I want to talk about, I'm going to start off from a weird place from a tweet
that I gave because I can't find anywhere else to talk about it.
Like this is why this needs talking about.
So I just want to sort of highlight some really cool stuff for people who are using PyCharm
and doing open source stuff that involves pull requests.
And these can be pull requests to your private repo.
Like one team member gave a PR back to the repo.
It doesn't have to be open, open source.
Okay.
So if you're using PyCharm, check this out.
Let me pull up this screen.
Come on.
Please.
Oh, I'm not logged in.
Oh, there we go.
I thought it might not.
Let me get the image up.
Anyway.
So check this out.
So people are probably familiar with the, the get support in PyCharm, you know, VS Code
PyCharm.
They all have really good get support.
You can see your changes.
A lot of times you have this, sort of over this gray little over overlay that says
who recently edited a file or a line.
It's really cool to go back with like get lens turned on for CPython.
Cause you'll see stuff from like 30 years ago.
Guido made this commit and here was the commit message.
You know, you're like, what?
This is crazy.
Right.
But working with PRs is one of the things that doesn't normally seem to fit.
And so I don't know when this got in there, but not too recently.
There's a, now a pull request tab.
So if you open a GitHub repository, if you're logged into GitHub and that GitHub repository has
a pull request and you open up the section, it gives you a list of all the open.
And I guess maybe you can toggle it close as well, but all the list of the open pull requests.
Hmm.
If you click on one of them, it'll show you all the details of the pull request.
The whole conversation.
If you click on that, who's the reviewer, you can change that.
Who's on a, who's it assigned to whether there's labels, whether it's been merged.
Wow.
And then like on the right, you have this whole conversation.
You can see sort of the flow.
This person commented this and they made these few more changes.
Then they commented again here.
This is all really pretty neat.
But the thing that is noteworthy, the reason I brought this up is there's a button that says
check out.
So instead of trying to create a branch or fork their repo and check in, like you just, I
don't know where this repo or this PR came from or what branch it was against.
I just want to check it out and run it locally, run the test against it, see what it looks
like.
Yeah.
Go.
Isn't that awesome?
Yeah.
That is really, really awesome.
I like it.
Yeah.
Cause normally you're juggling a lot.
Maybe you have CI, continuous integration that tells you like the linting pass, but other
times you want to actually just get it and run it and play with it and decide, you know,
did this make the code slower?
Did it make it faster?
Do I like how like the result of this feature looks, you know, especially if it's like a UI thing
or something.
Right.
So I think this is, this is super cool.
And the reason I bring it up is there's like nowhere in the documentation.
Like if you go over to PyCharm here and you look for pull requests, there's, they don't
even mention this.
Right.
So I don't think people necessarily know about this.
Like, it seems.
It's a stealth feature.
It seems totally worth highlighting because dealing with PRs in that way is actually kind
of janky.
Right.
It's like, it takes a little bit of understanding, get maybe more than, and GitHub more than a lot
of people would off the bat.
So if you just go click, check out, play with it.
Nope.
I don't want it.
Or yes, I love it.
That's, I think that's great.
I would still actually manage the PR and GitHub, but the ability to explore it super quick and
easy within your project, I think is super cool.
Yeah.
And quickly grab the code because I've, I mean, I know in GitHub, you can get it.
You can clone their branch and.
Yeah, exactly.
But it's hard.
It's like not too easy.
It's a, it's several clicks at least to find it.
And so, yeah.
Right.
And do you actually want it cloned to your, your account?
Maybe not.
I want to check out the code, you know, like, so grab the right commit, hash, shot, whatever.
Yeah.
Also really quick while we're on this topic, I just want to give a quick shout out to this.
So if you go to just the jetbrains.com/pycharm right now across the top, there's this, oh,
here, there's this cool upcoming webinar.
10 things, 10 get things you wish you knew in PyCharm.
Very oddly that, that is me.
So anyway, if you want to, I'm going to do a webcast next week on June 7th.
Oh, nice.
About a whole bunch of get fun things in PyCharm and UI tools and whatnot.
So if you want to check that out, they definitely can.
Cool.
Yeah.
All right.
So that's it for my thing though.
Check out, if you're using PyCharm, use, check out this pull request thing.
It's even in the free version of PyCharm.
So it's, it's worth noting.
Nice.
Huh.
Let's see a really, really quick real time follow up.
Roman Wright.
Hey Roman.
Says, yes, it helps you sort out PRs so much.
I totally agree.
And then Wolf says, is it available in IntelliJ and does it work with GitLab?
I don't know if it works with GitLab.
I'm quite sure it's available IntelliJ in IntelliJ because like PyCharm is just
basically specialized IntelliJ.
So I'd, I'd be very surprised if it weren't available in IntelliJ, but I can't say for sure
in GitLab.
I don't know if it's a documentation, but I also can't find that.
So anyway.
So on the PyCharm side, there's, isn't there supposed to like a new, some UI changes that
happened recently or, you know?
Anyway.
Possibly.
Oh, one of the things that changed recently that was, I actually kept stumbling into it
like on the Git stuff is they have little overlays of who made changes when kind of like that
Git lens from VS Code I described.
Yeah.
They started adding that and I kept clicking it by accident, trying to click on the line.
So that's like, why does it keep popping up a diff?
Oh, I see.
Okay.
So I kind of crashed into it, but yeah.
Okay.
Anyway, if you're doing PRs, check this out.
If you're doing PRs and using PyCharm, check this out.
It's definitely useful.
All right.
Well, so we have no guests.
So that's our items for today, right?
It is.
Well, we would be remiss to not have extras though.
Of course.
So yeah.
You want to do the extras first?
Your extras first?
Sure.
I just got one.
So the, it was a couple of weeks ago.
We, I think we talked about, about Pandas Tutor switching to Piedide, I think.
Yep.
So there's a, there's an article that came out on the Piedide blog that is a panda about
pandas tutors switching to, or Piedide, Piedide, Piedide.
Uh, and so, one of the, the reason why I bring it up is because there's some cool stuff
in here.
It's a, it's not just, Hey, we did this, but it's also, why did we do it?
And kind of walking through some of the stuff, how they did a self self-contained pandas tutor
wheel, you know, dealing with JavaScript and imports and all that sort of stuff.
And the fine tuning and what work has to go further.
So other people that are like, Hey, this Piedide actually proof of concept.
It's starting to look cool.
I want to do this too.
This might be a nice thing for people to check out.
So, yeah, this is super nice.
And I, I definitely think the, what are the rough edges and what worked really well?
Those types of lessons for now are going to be really valuable for people trying to adopt
this.
Yeah.
Well, that's all my extras.
Awesome.
All right.
Well, let's just make it a straight run for Piedide and Piescript right out.
So last week I did two videos on Piescript, which is based on Piedide as well.
So first one is a 30 minutes video.
I sort of hinted that I was working on this, but remember I said it wasn't quite released
yet, Brian.
Yeah.
Last episode.
So now it's out.
So now you can check out, I'll link to it.
You can check out my 30 minute Python, Piescript, WebAssembly, Python web apps running locally,
which is super fun.
It's all about not just, you know, let's like take some Python and put it in the browser,
but how can you use some like Piedash config settings to override where Piescript actually
comes from.
So the Piedide, the runtime comes from, so you can like put that locally in your app and then
download it offline and all sorts of fun stuff there.
Cool.
So basically building an offline progressive web app that is like, can be almost a hundred percent
offline.
This one calls an API, so it still needs this API.
Anyway, that was really fun.
And then the next day after releasing that, it occurred to me, do you know what supports
progressive web apps?
iOS and Android.
So I created a second video called Python iOS web apps with Piescript and offline PWAs.
And so here is, if you're looking at the screen, there's a, on my iPad, there is a web app that
runs Piescript talking to a Flask based API over the internet.
And it is basically, you can go up and basically say, install this as an app on my iPad.
And when you launch it, that install process already down downloads the WebAssembly and the
run the standard library and all the WebAssembly stuff that makes it large.
So you just boom.
And it opens up within like less than two seconds running Python client side on iOS.
That is so cool.
I'm seeing lots of uses for this.
I mean, people could do like dashboards of pipelines and all sorts of stuff and have them be on tablets
now.
So yeah, absolutely.
Yeah.
It's, it's, I mean, once you've already made it a progressive web app, it's like a few button clicks,
like this whole video about this iOS thing with like setting the stage and everything is, it's three minutes.
So, I mean, it's not a hard process to make it happen, but it's just not obvious.
And it's really cool that it works that way.
Cool.
Yeah.
All right.
Well, that's it for my items.
I do have a joke.
Nice.
And I know you might have a joke as well.
Yeah.
Awesome.
Okay.
I'll go with mine first.
Cause mine's easy.
And then I have a bonus joke for you based on your topic that I didn't, didn't see coming.
Okay.
So this one comes from Brian skin.
Thanks, Brian.
I just sort of pointed out a joke from Seth and it says people are out here just dangerously
thrown around SQL abstraction layers.
And if we aren't careful, someone's going to lose an arm and O R M.
It's pretty good.
Yeah.
It's really good.
Yeah.
Actually, if you are careful, you can lose your arm for good.
Yes.
And still be, still be all right.
Yeah.
All right.
So here, here's the, here's the real time joke, a followup that, based on your, your,
um, okay.
Regex one.
Ask me why I'm looking like this.
Why?
Well, that's just my regular expression.
It's terrible.
It's really bad.
All right.
I wish I had somebody in my life.
I could share that with other than you.
Okay.
If other people listen to the show, we could share it.
Okay.
So, the, there's like all sorts of AI and stuff going into, code editors.
Now that make them like do all sorts of stuff to help you out.
Right.
So, Kermit the frog looking out of, out of rainy window.
It's when you've barely started writing a line of code and your ID already lets you know about
three syntax errors, two runtime errors, a grammar mistake, five misdemeanors, contempt of court
and treason.
Joe's getting started.
Why is it so hard?
I love it.
That's really good.
Anyway.
Yeah.
I kind of felt that way today.
I was, I was playing around with some stuff.
I'm just like, what is good.
This is over the top.
This thing.
Yeah.
So, but no, good.
I'm glad the editors can help us out, but sometimes I feel like an idiot.
So yes.
Anyway, indeed.
Well, great being here with you.
Good being here with you.
Indeed.
Thanks everybody for coming.
Bye everyone.
Thanks for being here.
Bye.
See you next time.