Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to
your earbud. This is episode 272, recorded February 23rd, 2022. I'm Michael Kennedy.
And I'm Brian Okken.
And I'm Calvin Hendryx-Parker.
Hey, Calvin. So good to have you here.
I'm excited to be back.
Yeah, it's great to have you back. I also want to say this episode is brought to you by
Fusion Auth, a new sponsor. Thank you so much to them for supporting the show. Check them out at
pythonbytes.fm/fusionauth. More on that later. Calvin, it's been a while.
Since you've been here, but you're a frequent guest. How about just tell quickly people about
yourself? Sure. I've been a almost, I guess, nearly lifelong Pythonista at this point. I'm going back
a long ways, but started a company back in 1999 called Six Feet Up, where I am the CTO and co-founder.
And we are all things Python and all things cloud. So we're doing some cool stuff there. I've been
very involved in some open source projects, like the Plone Foundation for the Plone CMS. We're very
involved in Django as well. I'm sponsoring the Django Software Foundation. So super excited to be
involved in open source and all things Python. Right on. So if I was a company, a person said,
I need a Python app, I need some help with it, or maybe someone to even build it, I might reach out
to you all and you might build it for me. Yeah. No, we'd love to talk about those kinds of opportunities.
The harder and more challenging, the better. Yeah. Those are the fun ones. Yeah.
I agree. I completely agree. I like easy. All right. Well, I think this one you got here and this
for the first one, Brian, maybe not so easy. That's what's up with your mocking. Why is it not working?
Well, your mocks. So this is a great, actually, this is a rabbit hole, but well, mocks are a rabbit hole.
So Ned Batchelder, great guy wrote, he writes a lot of great stuff. Also maintains coverage.
But he wrote an article called Why Your Mocks Still Don't Work, which is a reference to an earlier
article he wrote called Why Your Mock Doesn't Work. And he wrote that in 2019. So if you haven't read this
first, so I'm going to go back and recommend both of these. So Why Your Mocks Don't Work,
or Why Your Mock Doesn't Work, is an excellent article. It starts talking about just like,
well, to think about how mocks work, you really have to understand Python name spaces and names and how
imports work and all of that stuff. And maybe you don't think you should have to, but you kind of do.
So in imports, those are not entirely obvious, like the way that that happens compared to other
languages, right? Where you just say, I'm using this library. There's like, it's way more direct.
So Ned starts off with like this really great example of just basically two variables,
X and Y pointing to a number. And if you assign into each other, but you don't really point at another
variable. You point at the thing that the variable is pointing to if you assign X to Y or Y to X or
something. And this hat, this does have to do with importing because the names that you import are
just kind of variable names that point to something. So he talks about namespaces and, and where, where
things point to talks about importing and the difference, mostly the difference between from,
from foo import thing instead of import foo and reference it as foo thing. Those are completely different
names within, within your Python application. So talk walks through that, talks about it and why.
So if you've got a value from one module pointing to an original value and then another one pointing to
the same threat thing, if you mock the wrong place, you're not going to get what you think is right.
So basically, and this is terrible to discuss over podcast. So I recommend looking at this,
because it's a really great example of how mocks work and, and why, why they act the way they do.
And you'll, you'll be able to fix a lot of your problems. So this is a good recommendation,
but the one that we're trying to talk about right now, why your mocks still doesn't work has to do with
this cool decorator thing that mock. I don't remember when a unit test mock added this, but there's a patch decorator.
Actually, I'm going to link to the show notes somewhere. We talk about the patch decorator and
it's, it's pretty neat. Actually, I'm jumping all around. Sorry. But if you just say like patch
something, what happens on your test? Like in this example, he's got two, you got a patch, cool feature
cool feature dot logger. And you're not patching it with anything with this decorator. What happens is
you're, you get these like other variables that you can add as parameters, mock prep and mock logger
that you can use those to change it. You can change the behavior, the, you can use asserts on it. You can
change the return values on these through that. It's a, just a, this is a way to get a handle into your
mock object. It's pretty cool. and, but the trick is they have to be in the right order.
And this example looks like it's fine, but you've got logger at the bottom decorator,
which is really the first and prep as the above decorator. And it's the, it's the first one,
Brian, it says the first line says this prep one. The second one says logger.
Yeah. But that's not the way it happens. So the catch here and the punchline is, it goes,
but when you're reading decorators, it goes bottom up, and, left to right.
Like onions.
Sure.
Right. Like there's layers around your code and like the inner layers, the first one it sees.
The second, so if you, the way he has it originally written, it just fails. It doesn't work.
the second punchline is unless you've got a real good reason to use, auto spec because auto spec
would have caught this problem like right away. And, what auto spec does is it says the thing that
you're mocking, you have to call it with the same interface that the thing had in the first place.
and, so if you've got a, a class or a module that has a function in it, you can't call
other functions. Whereas normal mocks, you can call whatever you want. so the default is free
for all. What you really should do is auto spec equals true. And really a lot of people, me included,
wish that that was the default to begin with, but for historical reasons, it can't be because it
would break other stuff. But anyway. Yeah. Yeah. if it's not the default to start with,
if you put that in to say now only behave as if you are the thing that I say you're pretending to be,
that's going to crash a ton of stuff. Yeah. So, yeah. And then the third and final punchline is,
uh, just don't use mocks. even he Brent mentions it in both articles, avoid using mocks if you can.
So absolutely. Felix out in the audience says tiny feature with a lot of power, this auto spec.
Yes. Very much like Yoda would put it. I love it. All right. What do we got next? Calvin thoughts on,
on mocking real quick before we move on. I'm, we are just diving into that and I don't do a lot of
the test work myself. So I'm sure Brian is the super expert on all things, by test, of course. So
I don't have a huge opinion here on specific mocking. Although I think it is important for folks to
realize that, yeah, decorators go from like that closest to the function out. It was an important,
uh, call out there. Yeah. The other one was from thing import something. And then you patch the thing
inside there. It's kind of that, that I actually, that was news to me. That's very interesting.
All right. Also news to me, please, please tell me about this. Chris may thank you, Chris may for
sending this over and wow. I don't know if you've heard about please folks, PLS as an LS
replacement for Linux and macOS, but wow, this thing is cool. was this, had either of you heard
about this? Not until today. And I went and installed it as part of my demo so I could see it because it
looks pretty darn awesome. So this is an LS replacement and I know there are other LS replacements
that already exists. So you can do more things, but this is a developer focused one written in Python.
That's pretty darn awesome. So if you go look at the image I linked to, or just go check out the site,
you can see that if you say, so I've alias LS to PLS. And if I just say LS, it shows you the contents of
your directory folders on top. And then it has icons for the types of files that they are. So I did an LS,
there's a Git ignore. So it has a Git branch icon. There's a license with the law. There's a markdown
file. There's a Python file, the Python logo, but it goes beyond that. Like it understands your Git
ignore and the files that are considered hidden are the Git ignored ones as well. And it won't show you,
even if you do like a hidden file listening, it won't show you things like the .es underscore store
on macOS because that's in the Git ignore. So the structure that it gives you is related to that.
Also for Python, if you have a virtual environment, it'll treat that directory as hidden. And because
the directory is hidden, like it's sort of suppressed in its visibility. So there's really cool features
around this that have to do with basically saying, all right, you're a developer, you're listing files
that are probably developer like. Now what, now what do we do? So another part that's cool is you can do
and please --details, which I alias to L because that's the LS like equivalent. And in this
world, it shows you the same types of things, but it also shows you the size in the human terms. So
instead of like one zero one, one, one, two, one, one, seven, one, one, one, two, it would say that's
10.2 gigabytes, which is nice, but it also shows you the Git status in the listing. So like it has a dash
M next to a file I modified and so on. What do you all think of this?
I think it's excellent. The, I tried to use it and failed and you've helped, helped me understand why,
because you, it has, you have to have fonts, it's like some special fonts installed, right?
So one of the questions when I posted this week was people like, how does it have custom icons?
What magic is this? Cause this will work over, like if I SSH into somewhere and install please on the
server, as long as my local terminal is set up correctly, this will work. And like, how does this
work? Well, the way it works is you have to have your terminal font set to a nerd font. So I've talked
about nerd fonts before, but all these nerd fonts have all these special icons in them. And long as your
active terminal font is one of the nerd fonts, then you get all these cool behaviors. If you don't,
you get squares, which are less than awesome.
My only complaint with it is that I wish it would have emulated more of the flags from standard LS
so that it just kind of work a light. I installed it. The first thing I did was like, please dash AL
and I got like a no, no L flag.
We don't know what that is.
Yeah. I didn't know what that was.
Yeah. It's kind of its own thing. That's why I did the alias on it. And I'm like, okay, well,
I'll just, I'll do these things. Another thing that's interesting, it has a, you can set up these,
these YAML configuration files that control how it looks. And then you can put those kind of like
node JS does with node modules. Like you can put it at different or the project.json, you can put it at
different levels. And if you go into a certain project that you had of a configuration file in
there somewhere, it'll pick up that configuration and then use that to like customize how it looks
for those. So that's kind of an interesting thing as well.
That is awesome. I mean, we need more, we need more like fun stuff in our terminals as developers.
I totally love this. This is absolutely the way to get people hooked on using the terminal in the
console. Yes. And I was thinking about like server management, which we'll get to later,
right, Calvin? Yeah. Yeah. But if you want to go into the server and so I'm going to SSH in and do a
thing like this is your entire user interface. Yeah. To that. Sure world. And so, yeah, yeah,
this is your world. So this is a way to bring like a little bit more UI information rather than just raw
white text listing a files. I feel like there's like actually a lot of value in this. Oh, totally.
Awesome. Let's see a Dean out in the audience and former. Yes. I thought my life was complete until
today. I didn't know this was missing from my life, but it is. Yes. Please more terminal stuff.
Absolutely. Well, speaking of more terminal stuff. Yeah. Speaking of more terminal stuff. Yeah. Take it away.
All right. So we over at six feet up, we've been very focused on the developer experience. And so
once a week we get together and talk about just, we can do a called code review, but it really,
it's more of a show and tell. And this is something I showed off last week at our code and review and
show and tell, which is a terminal that is GPU based and written in Python. And it's called Kitty.
If you've not used it, it actually is a super awesome, super fast. Basically, I don't know. I found it to
just be a super smooth experience. And the reason I had revisited it was I'd been using Tmux forever.
And before that I was using screen and I wanted to like, just have the ultimate power tools available
to me as a, as a developer. And as a, like my primary mode of operation is basically hanging out
in the shell or an editor all day long. So I want the best tools possible. So I'd highly recommend
folks check out Kitty. It is absolutely tuned for performance. And you may ask, well, why the heck would
I want a GPU enabled terminal is just showing me text is because I want the most performance
possible out of my, my system when I am using it. And so I actually was going to give a quick
little demo here of Kitty. This is actually using PLS. And obviously, yeah, I see it.
I have the right.
And what is this? Oh, my, is this on my posh also? What do you got for the,
Oh, for the bullet train down there. So it's actually bullet train core.
it's not maintained anymore. That's probably my next, my next venture is going to be replacing
that line with some new or something like that. Exactly. Some new, you know, system for showing
my awesome, like prompt up there. But yeah, if you get the right fonts installed and all that Kitty
supports all that stuff seamlessly, it's very, very fast. And one really cool thing, since we're all
like Pythonistas and people who are listening to this would totally relate. You can extend Kitty
with kittens that are basically Python plugins for Kitty. so if you actually, I'll, I'll give
you a quick example. So if I run Kitty, I, it is, I love, but I love it. I kind of love it actually.
So you just, you invoke Kitty with the kitten flag and say like what kitten you want to use. In this
case, I'm going to use iCat. I'm going to just basically echo out a Slack emoji that we use for Python.
Oops. Oh, oh no. Is this like going to be like the, total like demo guys, not, not being very kind
to me now.
I love that your, your prompt has the Python version and stuff in there. That's great.
Oh yeah. If you're in a specific like pyenv area, it definitely shows up. Let me just,
let me just like try it here. iCat Python. Oh, there we go. So I must've just been in the wrong
directory, but so you can actually show graphics on the screen. So if I want to look at an image real
quick, I don't need to go to finder and open up preview and like do a quick look on an image.
I can actually like, you know, quick look on any image I want. And I, one of the things I did want
to show off, I go back to the director. I was, people who are listening, this looks like a full
high res image in the terminal. Yeah. Based on a PNG. So I used iCat, which is a kitten to display an
image directly in the terminal. And now if I wanted to do show even something coolers, because one of the
features of Kitty is it's basically got a graphic subsystem in here. And if I wanted to like, look at my
markdown files, normally if I'd use bat to look at my markdown, like for the readme that's in here,
you know, you get the kind of content highlighted markdown, kind of cool, not, you know, not super
great. But if I do MD cat, which is Kitty enabled, it actually leverages the Kitty subsystem here.
I can actually review my markdown file with images in line. So you can see that the XKCD cartoon is
actually embedded into the readme of that document. And it does a little better job of like coloring and
highlighting the syntax. So if you want to preview markdown documents without again, not going to
preview or not going to like rendering it to HTML and viewing your browser, you can actually view it
right in your terminal with the images shown in line, which is super awesome. And one last thing,
one more trick I'll show you. There is a Kitty kitten for viewing diffs in a rich tool. So if I do
get a diff tool, I've configured with my, you know, dot get config to configure an alternate diff tool for
diff. And now I get this really beautiful, you know, high res graphic representation of my diff,
my files. So really kind of pretty, you can see there's two, two diffs, two different files,
I can page through the different files and it shows me, you know, side by side, you know, diffs.
Is that still in the terminal?
That is still in terminal. I did not leave my terminal.
It looks like a new window.
It did. It looked like a new window, but it's actually all in terminal. So you can stay in
your terminal, stay at your keyboard and all the, all the shortcuts are super nice. One last thing.
The diff just sold me. So yeah, you can split your windows, obviously like, you know, other kinds of
terminal emulators, like if you're using Tmux, but then it's got all the layouts built in. So if I
wanted like horizontal or vertical or a grid, or if I wanted to like, just get to the current one I'm on,
you've got all that available to you with nice shortcut keys and you can just, I got rid of Tmux and
started just going all in on kitty only.
Okay. I got a question. So I've always been confused about this whole windowing thing because
I just opened another terminal. so.
Oh, Oh, I see what your question is. I don't want to open another terminal. I don't want to reach for my
mouse when I have to like go between terminal windows. So I'd rather have like multiple tabs and then have
splits. And so I can have like a paging going on in one window or another window. I can like, you know,
then edit these things, make them like shorter or taller or split them in a different way.
So I feel like just keeping my hands on a keyboard keeps me more productive as a developer,
as opposed to reaching over for the mouse. I know it's not that far away, but I feel like it breaks
that flow. If you're, you're typing away at code and you want to like quickly, like open up a tail
for a log and like a same window right below where you're running the process. You're just,
you know, a couple of keystrokes away and you've got that open and going.
Cool. Nice. Yeah. Yeah. Oh, that's really cool. So I know we're not to the joke section yet,
but you know, the joke about how do you generate a random string, put a new computer science
student inside of them and ask them to exit. Yep. So I think the new version is put four of them in
these different panes controlled here and ask them to exit the top right one.
Here, I'll do it right now.
Even more random number or word.
There we go. Boom. Did it.
I'm going to try kitty. This looks great.
It's super configurable. It supports all the nerd fonts, all the color schemes. I've got,
you know, just got, there's a bunch of cool plugins for it. I've got a search plugin,
which searches through your back through your terminal. And so if I was, there's nothing in
that specific one, but if I searched through here and wanted to search backward, it uses FCF to do
searching backwards. So if I was looking for like LS, you see it highlighted the word LS or 2020.
And then if I had multiple ones and I could just arrow back up between them.
So it's all built in.
Yeah. Yeah. Really cool. Also really cool is our new sponsor, Fusion Auth. Thank you
them for sponsoring this episode. So let me just tell you really quickly about them. They're an
authentication and authorization platform built for devs, by devs. It solves the problems of building
essential user security without adding the risk and distraction from your main app. Fusion Auth has all
the features you need to, for great support at a price that won't break bank. And you can either do
self-hosting or you can get a fully managed solution running in any AWS region. So if you've got a side
project that needs a custom login registration or multi-factor authentication, social logins, or user
management, you can download Fusion Auth and get the community edition for free. And the best part is you can have
unlimited users and there's no credit card or subscription required for that. So check them
out at pythonbytes.fm/Fusion Auth or just click the link in your podcast player show notes and,
let them know you came from us. I want that t-shirt. Thank you, Fusion Auth. That's cool. I know.
Yeah. You got, get a cool t-shirt, cat slash et cetera slash password, D. Yeah. Very cool. Nice. I love when you get a cool t-shirt from our sponsors. All right. Well, Sue doesn't like cats. I know. And kitties. And kitties. And kitties. I can tell that you're already a fan of kitties. well, so, I don't know if, kitty is parallelized, but,
Yeah. So I want to talk about parallels and parallelization say that three times. anyway, I found this article, by, Jamie Welta. Cool. Last name actually. but it's called futures and easy parallelization. And, I was like, you know, it was a pretty short article and I was like, it can't be that easy. but so this isn't talking about, AIO stuff, ACE or asyncio. It's, it's talking about
this one is talking about thread futures with threads. And this is, it's a, it's pretty cool. The idea is you've got just maybe you've got, and it starts off with a simple example. I just have some work that I want done and I want it done on, on different threads or different processors. So, this, this example, brings up a thread pool, a thread pool executor, and then runs them all at the same time. does an executor submit?
And it's just a small snippet of code. It's just a handful of lines. And then I tried this out. So this example actually, is kind of boring. It's just doing, like a power X to the power of two, or X squared. I'm on a couple of things. I think that's what star star is, isn't it? Is that power of, I don't remember.
Yeah. X to the power of two X. Yeah. X squared.
X squared. So, the other example seems a bit, a bit more, down to earth and that's, and yes, on our screen, on the, on the YouTube screen is just, it's the entire program here. it's just, you're taking a few, a few websites and a couple of pages to go to.
And, and then actually just slurping those down with requests and grabbing something about them. And this example just, as the result, whether it's a 200 or something like that, but it's a really short example.
And you've got parallelization going on. And I played with this, just downloaded it. The only, we'll have it in our show notes. The only error on this that I had to do is it's using, it's using time in here is just like a debug thing. And in the example, doesn't import time. So you have to add, add that import time. And it runs just fine like this. And this is a pretty quick way to add parallelization for some quick task.
So I kind of like it. There's occasionally, especially like I would do it. there's a lot of huge log files I have to parse or, or big data files that I'm looking for stuff on or grabbing, grabbing error logs off of different systems. And this would be a great example to just grab, grab them all at the same time and pull them in. So.
Yeah. Yeah. Yeah. That's nice. You know, one thing that's cool about the futures you get back from the thread pool executor is you can say dot result and it blocks. Whereas on asyncio, it throws an exception and says it's not done rather than just blocking.
Oh yeah. Yeah. And that's the article kind of talks about that. It's one of the simplest things is you, you tell the executors, you call executor submit and that gets the jobs ready, but that doesn't block. Those are, you can, you can submit as many as you want.
And then in the example, he's just using few like future dot result, in a, in, in a list comprehension and that for each of those result that'll block until the next one's done. And you know, this one's doing it in an order of which one you submitted it, that might not be the order they finish in, but you don't really care because you just want to wait till they're all done anyway. So.
Yeah, exactly. If you block on the first one, it's not done. The second one might finish first, but it'll be done by the time you get to them. Yeah. Yeah. Yeah. And this is a lot more natural for folks who may not be used to like asyncio too.
Oh, I've been deep in the asyncio world.
Well, it's all built natural here.
And that's, that's.
And I have scars now, let me tell you.
That's exactly why I wanted to bring up this article is because there's a lot of stuff where like a, like a, maybe a DevOps person or something.
They're not, they're not writing async programs, but they might have a async need or asynchronous needs that can be solved with a simple, some simpler code.
So.
Yeah. This is very, very elegant, easy to understand.
Yeah. Nice article.
Good one. All right.
Well, I want to talk about databases and more tools.
I feel like this is just the tool focused.
Like the tool episode.
It is. It's full time.
All right.
So I did an episode on talk Python with Emily Morehouse, glyph and Hennick and Hennick pointed out this thing called PG mustard.
Have you heard of this?
No.
Have you?
Oh, well, I just listened to that excellent episode and heard about it.
So now, you know, but other than that, like I had not heard of it, but one of the challenges, so many websites, I just don't understand why the world works this way.
But you go to the website and it just spins and spins and the clunkier, the more internal the thing looks, the more likely it is to take 10 seconds to do whatever it's doing.
Right. But, you know, it's doing some database query, probably without an index.
Maybe they gave it an index, but the index is not being used because it's actually filtering first on some other random thing or whatever.
So databases have this cool feature to say, given a query, explain how you're going to execute this.
MongoDB has this.
Postgres has this and so on.
OK, so that's that comes out as text.
What if you could have a better way that gave you advice?
And that's what this tool here is, which does cost money.
Just to be clear, it's a commercial thing, but I thought it was cool enough that I wanted to point it out to people.
So what you do is you give it your basically a select statement and you ask it to explain it and it will it'll break down the explain statement into different sections and tell you this part is really good.
This part of of the query could be improved and so on.
And then it gives you so like it'll it'll show you this beautiful visual way of explaining it and you can dive into it.
And if you click on it, it'll tell you things like, OK, this is a nested loop.
And on this part of the query, it took one hundred and fifty two milliseconds.
You got one hundred rows back.
And then it actually describes the situation, why it's good or bad.
So, for example, it says you got five stars because you discarded one point three million rows.
That makes it faster.
But you only got three point two stars because the row estimate was out by a factor of 42.
You know, try to get that from text, right?
This is this is super helpful if you've got a slow site that you want to say, OK, this page is slow.
These are the three queries that run when we pull this page.
Why are they slow?
How can I make them better?
So it's you know, we talked about the regex one on one thing, how it like kind of guided you through and gave you recommendations.
This is like the database equivalent.
This is nice.
This is awesome.
I can't believe I've never seen this before.
Well, I know I have.
I can't either.
I've never seen it either.
Now, from the from the interview, it sounded like it would recommend how you could change your query to make it better.
Is that something it has in there or did I imagine that?
I believe so.
And I believe so.
If you like open up this 3.2 stars, I think it'll give you descriptions about what could be better in there.
So it can give you performance advice, including high index potentials or index efficiency, disk operations.
So like you've got to read too much off this to answer this question.
Poor cash performance, excessive heat fetches, read efficiencies, glossy bitmap scans and on and on and on.
Right.
So it's pretty cool.
It runs on Postgres 9.6 or newer.
I hope you're newer than that 9.6.
That's that's pretty great.
It supports that far back.
Yeah.
Anyway, it is a paid tool.
But if you could for ninety five dollars, make your website ten times faster and people have been complaining and complaining, you don't have to rewrite anything.
You just put in like a slightly different hint or index or change the order of a query like that.
That's that's worth a lot.
I think I'm just going to try to learn this and then set up a page to say I'm a database optimization consultant and just run this in the background and say, yeah, look, five hundred dollars an hour.
I will absolutely come in there.
Yeah.
And I have this new business proprietary set of tools that I've I just I can't talk about it.
But you let me in there and magic's going to happen.
I shouldn't have said that out loud.
Yeah.
Well, I guess that the market will be swamped with these folks.
Yeah.
Anyway, I thought this was cool.
So I wanted to give it a shout out.
Cool.
Nice.
That is super cool.
Yeah.
All right.
Calvin, you got the last one.
All right.
Last one up.
Continuing the tools parade.
Another tool.
This is also cross platform.
I didn't mention that before.
One of the reasons I really like Kitty was the fact I can use it anywhere.
Linux, BSD, Windows, Mac.
There are downloads for all those platforms.
This one doesn't support Windows, but it does support Linux, Mac and FreeBSD.
It's BPYTOP.
I used to be a longtime user of Glances.
And if you didn't know what Glances was, you were also missing out.
Because Glances is an awesome way to see what's going on in your system.
Like what I was being used, how much memory is being used, how much swath is being used.
And BPYTOP is kind of the next generation of that.
So I will show a quick little demo of this one as well.
So for those of you who weren't familiar with Glances, this is what Glances looks like.
Sorry, a little interruption there.
But while I'm live here on the podcast, this is Glances.
It's kind of like more tech, very tech-y, kind of old school looking.
But if you just PipX install, and that's how I typically install these kinds of tools.
Sorry about that.
It's all good.
PipX is the homebrew.
Oh, man.
It's amazing.
Python things, right?
You just PipX install BPYTOP.
If you don't have PipX installed, you should install PipX because that'll get you access to all the stuff and your path all set up.
But now I just use BPYTOP.
And you get this nice colorized view of a dashboard.
It's all really just laid out well.
And then all the, you can kind of see on here, there's like characters that are shaded in a different color.
If you, you know, hit those characters, you'll be able to like resort.
Or if you see the little numbers, I can hide and show the CPU or the memory graph if I don't care about that one so much.
So for people who are just listening, here's a terminal app that has like task manager.
Oh, yeah.
Or activity monitor levels of sort of graphs going on of like, here's the CPU over time.
Here's the running processes sort of by CPU.
Here's the network.
This is probably more useful than activity monitor, honestly.
Oh, I think it is.
I mean, what's nice is you get that trending metrics over time.
So you can see by CPU core or by like kind of aggregated CPU view, how, you know, if you're seeing spikes or what.
And this is really useful if you're on a server and like something's periodically happening, you're not sure what.
And you can kind of track down like either IO issues or CPU spikes.
And you can kind of see if they're becoming very like periodic.
Maybe they're happening every minute or every like five minutes, like on the dot.
And you're like, oh, that's weird.
There's something like maybe it's this cron job.
So it helps you track that, track those kinds of things down.
You can also inspect the processes so you can arrow up and down and you can actually like hit return and see like what CPU specifically or memory like a specific process is.
You can like dig down into a specific process and see what core it's actually running on.
It's just, again, for tracking down performance issues.
I'm just using it locally on my own laptop right here.
But I've used this numerous to every machine I log into for, you know, customers or production type stuff.
They're still using virtual machines.
This is absolutely installed so that when they're like, oh, something's slow or something's doing weird.
Like I just go fire these up and take a look real quick to get kind of a snapshot in real time what's going on.
I've done that with glances.
Yeah.
That was used to my go to.
But I just found B5 Top was like the super powered version of glances.
Interesting.
You've moved over.
Yeah, the graphs are way better.
Yeah.
Like you have progress bars or like meter bars that are graphical in glances if you make it wide enough.
But they don't have over time.
They're just like snapshots.
And these are like beautiful gradient colors.
Like I kind of just expanded the net one so you can see the traffic going across my card.
You can also switch back and forth between different interfaces on the system.
So if you've got multiple network interfaces, you can see the aggregate or just for a specific interface.
Yeah, super helpful when trying to track down, you know, weird, you know, in quotes, weird issues.
How's it run on Kitty?
It runs great on Kitty.
The performance is amazing.
That's another thing I didn't show you is like you can actually see with the NVIDIA SMI tool.
Like there is Kitty using up 20 megabytes of my GPU memory on there.
Oh my goodness.
No, that's pretty awesome.
Speaking of beautiful, Alvaro says B5 Top has themes.
Yes.
They use the Darkula theme.
Yeah, I love the fact that anything's got themes I can customize like, you know, Kitty or even B5 Top or whatever my IDE is.
I just, I trick that stuff out.
This is my environment.
I want to be as comfortable and as productive as possible.
So the more customizable, the better.
And the more emojis, the better.
Love emojis.
Yes.
There's something to be said about it.
If you sit down and you're like, I am excited.
Look how cool this is.
I'm excited to play with this.
Yeah.
You're like, oh, I'm using like an old version of Bash with nothing else installed.
This is not as much fun as I envisioned it to be.
Well, the only issue is when you sit down with someone who's like, they fire up text edit to like edit some text.
You're like, what are you doing?
Like, come on.
Like, let me show you some cool tools.
Like, let me get you up to speed on here.
Yeah.
Text edit being the notepad equivalent if you're not a Mac person.
Yeah.
That's maybe it's a word pad.
You know, maybe it's a word pad level.
Like, that's probably where it, which is worse.
I think that's worse than notepad.
It is.
Because you're going to get weird, corrupted characters that you're not going to know.
Yeah.
Oh, man.
One of the, especially with, with working from home now, a lot of people are, are working with kids around that walk by and you want your job to look awesome.
So that they're interested in what you're doing.
Just saying.
Yeah.
I'm sure my kids think I'm a hacker.
You're not, wait, you're not a hacker.
Well, I hack on code.
Yes.
The, the original, the original.
Exactly.
The original meaning of that word.
Yeah.
Brian, time for some extras.
I do have a big extra that I'm really excited about.
Yes.
The book is, which I've been talking about for about 18 months.
And if you add that to the previous 18 months, about three years of this podcast has been talking about this book.
But anyway, so it's, there's no longer a beta flag on it.
It's not in beta anymore.
So it's, it's off to the printers.
And, and then to celebrate it being officially released.
It is, there's a coupon code that we'll link to this page in the show notes, but it's a coupon code.
I don't know how long this is going to be good for, but this is for 40% off the ebook.
So this is exciting.
And I don't have a physical copy yet.
I'm still waiting for mine to get delivered.
Hopefully it'll be in the next couple of weeks.
So, yeah.
Anyway, that's, that's one of my extras.
The other extra I wanted to bring up is a pie camp.
Spain is happening.
April 15th through the 18th.
And man, this looks fun.
It's like actual camping.
I love the idea.
Well, like, I don't know if it's actual camping, but there's a, admission includes, four days and three nights, including accommodations and breakfast, lunch and dinner provided.
This is a pretty amazing.
I know, Brian, I see karaoke on that list too.
Karaoke talks.
Yeah.
Games, ping pong.
Ah, this looks great.
You have to give your talk in song form.
Yeah.
Oh man.
No one, no one would want to see me do that.
No one.
Or me either.
So this looks great.
It does look like a lot of fun.
Fantastic.
Calvin, you got anything extra you want to throw out there?
I do.
coming up next month and just a little over a month is the Python web conference.
Oh, I've got the, let me pull up the slide for it.
You've got the screen.
I do have the screen for it.
I had even, even pre-planned for this to be ready to roll.
So it is Python web conference time.
this is our fourth.
Got any good speakers or what?
Fourth annual event.
we've got some amazing speakers.
who are going to join us this year.
So I'll actually bring that up because I'm really proud of this group.
if you scroll down through here, there is just a amazing, bunch of people who have
signed on for this amazing adventure with all of us, over here.
So definitely check it out.
It's going to be way bigger than it has been in previous years.
So this is the fourth year we've run it.
And I believe we've got 90 speakers this year.
We are doing, five tracks across five days.
So there's two app dev tracks, a culture track, a cloud track, and a pie data track.
so there is something for everybody.
get your tickets.
Now it is going to be a ton of fun.
We will start, you know, getting things cranked up a couple of days beforehand.
We've getting, you know, the Slack channels all set up and people can start basically hanging
out.
And we're going to have some cool socials.
I know we've got one of our speakers is going to give a mindfulness, social.
So if you want to come and learn how to decompress as a developer, and she's going to actually
be one of our keynotes about burnout.
but she's going to, you know, give a practical example during one of the socials that I'm super
excited to try out.
Nice.
Fantastic.
Yeah.
I see a bunch of the people in the speaker list have been here on the show.
Yeah.
These should, these should, these should not be strangers to, especially this guy
right here.
He's definitely not a stranger.
I don't know about that guy.
He's shady.
Definitely shady.
Well, I was, I'm noticing a lot of these speakers from either this, show or talk Python
or, testing code.
They've been, a lot of people have been one of those friendly faces, a lot of friendly
faces on here.
And again, great, great group of people.
They're all super excited to participate in the conference.
They're all super excited to like hang out with everybody and like, just be a part.
Yeah.
I like that you're putting, the social links up on the page so that people can check
that out instead of having to Google for them or something.
Yeah.
It's all about the people for me.
I mean, I'm, I'm, I love being a community builder and, and putting this together for folks.
Oh, look, there's another amazing speakers in the, in the audience right now.
Fantastic.
Yeah.
That is awesome.
Well, how about, no, I don't mean to cut you off, but I was just curious if Michael had
any extras.
You, you know that I do.
All right.
I got a couple.
Let me, let me tell you about this little app I got, which I meant to do a little video
so I could show you.
I'm a huge fan of macOS and, I really enjoy working there.
I love the, like the terminal tools are like server stuff, but it's not, you know, you got
all the nice little tools and whatnot.
One of the things that I absolutely just don't understand is switching between windows is like
nearly impossible if it's the same app.
If I got one web browser set of tabs and another, I'm going to cycle between them like command
tab, the alt tab equivalent has no effect on that.
Right?
Like why is this?
So I found this cool app called witch that lets you do all sorts of stuff.
like, you map it like alt tab instead of command tab and it'll pull up.
It's very similar, but then it'll, you can even like switch between tabs within a browser.
So I want to switch to Vivaldi, but onto this tab of that Vivaldi.
So how, wherever it lives on what Vivaldi window, I don't care.
I just want to go to that tab, stuff like that.
Super, super cool.
It's just cycle between the last use window instead of the last use app.
And there's just a, the customizability of it is insane.
Like it's, it's truly a crazy.
And what does it cost?
It costs $14 once.
So if that frustrated you, check that out.
Number two is I did this video called don't use loops.
Or do you actually need loops in Python?
It was really to say like some of the time you can use comprehensions of various types.
That already talked about.
But in response to that, someone said, oh, I don't really think there's any difference
between using a list comprehension and a for loop.
They're the same.
Like, how could you even tell me that they're different?
Well, one import dis from, from dis import dis, dis like,
disassemble and you'll see a big difference.
But two, I put together an example that for 10 million times,
basically adds the numbers one to 10 million,
even numbers one to 10 million to a list using a for loop
and then using a list comprehension.
And it is about 25% faster to do the list comprehension than the loop,
which isn't going to change people's world probably,
but it's, you know, something to consider.
Yeah.
So I'll link into a very small gist there.
I just.
My, that peeve of mine.
If you're going to do a loop, at the very least,
don't do for I in length of something.
That's C.
That's not Python.
Yes, please.
Or, or create a number.
Count equal, you know, I equals zero.
While I lessen this, I plus plus on the inside, right?
Like, yeah, there's a lot of bad variations.
Yeah.
Those are, those are, I intentionally put things like that in interview questions
to try to see if people are really Python programmers or if they're.
Yeah, exactly.
And it might be fine that you're a C programmer coming into Python,
but sometimes people will be dishonest with you during the interviews.
Like, oh yes, I use Flask all the time.
All right, how about you create a hello world view and run that?
I can't, I can't do that.
Okay, well.
Then you probably don't use Flask all the time.
You might use it sometimes.
They're not, not eight hours a day like you told me.
All right.
Another thing, another similar little gist thing is I was working on using a database API
that is async only, but I want to use it in the web app that is not async at all.
How do you do that?
All right.
We talked about like the result and blocking and all how painful that is.
So I came up with this little gist that was working great in production, in dev.
So this really simple thing, you can just wrap up an async call and say, run it.
It internally manages a little loop and it calls run async.
So you've got like a database async call.
You can just say, you know, go to the call and just say, run whatever, get the thing async
with the parameters, right?
So it's not like a decorator.
You just call it really simple.
Well, in practice, what I found trying to deploy this to a website was the database
back end was doing weird stuff with like what thread it's running on.
The web server, MicroWhisgi was like shuffling around like the order of when stuff ran on different
threads and it was freaking out the event loop.
And you get all these errors about like, this thing has become detached from its asyncio loop
or it came from one loop and it's trying to continue on another loop.
Just like, oh no, what is all this?
So I ended up coming up with a massively crazier version that people can check out that basically
coordinates all the work to a background thread, runs it all in the same place and puts it back.
It works fabulously.
It is horrifying.
So you can take it for what it is.
Anyway, as part of this conversation, maybe it works really well, but it looks really bad.
Bill Jones.
So from court, I believe sent over a thing that said, one of the problems with asyncio is if it's
already running and then you call async version, which internally happens to use the same pattern,
it's going to crash and say it's already running weird.
So there's this thing called nest IO, which allows you to basically have a reentrancy.
So if you get the runtime error, this event loop is already running.
Well, if it is just run, you know, whatever.
But that's the error you get.
So this will allow you to basically re like continue on in the same loop.
All right.
Those are all my extras.
I thought those were all a little fun.
Nice.
I can't believe combining threading and asyncio in the same little submodule is brave.
I did not get to that position willingly.
Not at all.
Like, but everything I had tried, it didn't matter.
And people say, oh, you should use asyncio dot run that manages it for you.
Yeah.
Except for that.
It wasn't working in the weird web servers that are doing all sorts of threading tricks and
just right.
Like it was the only thing that worked.
And so there it was.
All right.
That was not funny, but maybe I've got something funny for you.
You ready for a joke?
Yes.
Always.
Okay.
So this one is about mistakes that people make with testing for truthiness versus assignment.
And so it's a cartoon and there's these humans being ripped apart by robots.
It says, oh no, the robots are killing us.
And someone asks why, but why we never programmed to do this.
And then there's like a computer with some code on the screen in the background.
You see robots killing people.
And it says, it has actually the code for the robot.
It says, void, interact with humans.
If is crazy robot equals true, kill humans.
Else be nice to humans.
But it's an assignment, not an equality.
It's a single equals instead of a double equals.
End of the world has come because of that.
You've just assigned it to be a crazy killer robot.
Crazy murdering robot.
Yes, exactly.
Yeah.
Nice.
Anthony would save us from this cartoon apocalypse by saying this, you know, remember your unit test.
Yeah.
And beta testers.
Why do we keep losing QA people?
I just don't understand.
Where do they go?
I don't know.
Just ship it to beta.
Yeah.
Yeah, exactly.
Exactly.
What could go wrong?
Segment your population.
A-B test this stuff.
Anyway.
No, thanks.
Nice.
But thank you, Calvin, for coming on the show this time.
It was totally fun.
Love it.
Yeah, absolutely.
Brian.
Thank you.
Good to be here.
That was a good time.
Yeah.
Always.
See you later.
Yep.
Bye.
Bye, everyone.
Thanks 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.
Get the full show notes over at Pythonbytes.fm.
If you have a news item we should cover, just visit Pythonbytes.fm and click submit in the navbar.
We're always on the lookout for sharing something cool.
If you want to join us for the live recording, just visit the website and click live stream
to get notified of when our next episode goes live.
That's usually happening at noon Pacific on Wednesdays over at YouTube.
On behalf of myself and Brian Okken, this is Michael Kennedy.
Thank you for listening and sharing this podcast with your friends and colleagues.