Python Bytes - #272 The tools episode

Episode Date: February 24, 2022

Topics covered in this episode: Why your mock still doesn’t work pls Kitty Futures and easy parallelisation pgMustard bpytop Extras Joke See the full show notes for this episode on the website... at pythonbytes.fm/272

Transcript
Discussion (0)
Starting point is 00:00:00 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 Ocken. And I'm Calvin Hendricks-Parker. Hey, Calvin, so good to have you here.
Starting point is 00:00:16 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 slash fusionauth. More on that later. Calvin, it's been a while since you've been here,
Starting point is 00:00:30 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
Starting point is 00:00:49 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, 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 for the first one, Brian, maybe not so easy.
Starting point is 00:01:30 Not so easy. 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, he writes a lot of great stuff, also maintains coverage.
Starting point is 00:01:48 But he wrote an article called Why Your Mocs Still Don't Work, which is a reference to an earlier article he wrote called Why Your Moc 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 why your mock doesn't work is an excellent article, it starts, it starts talking about just like, what, well, to think about how mocks work, you really have to understand Python names name spaces and names and how imports work and all of that stuff and it maybe you don't think you should have to but you kind of do so and imports those are not entirely obvious like the way that that happens no compared to other languages right
Starting point is 00:02:38 where you just say i'm using this library there's like it's it's way more direct so 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 and to 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 uh the names that you import are just kind of variable names that point to something. So he talks about namespaces and where things point to, talks about importing and mostly the difference between from foo import thing instead of import foo and reference it as foo thing. Those are completely different names within your Python application. So walks through that, talks about it and why.
Starting point is 00:03:34 So if you've got a value from one module pointing to an original value and then another one pointing to the same 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 mock 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
Starting point is 00:04:22 link to the, uh, show notes somewhere. We talk about the 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?
Starting point is 00:04:36 Like in this example, he's got two, you got a patch, cool feature dot expensive preparation and patch, 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 um and but the
Starting point is 00:05:15 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 first, and prep as the above decorator. It's the first one, Brian. It says the first line says this prep one. The second one says lager. Yeah, but that's not the way it happens. So the catch here and the punchline is when you're reading decorators, it bottom up um and uh left to right like onions sure right like there's layers around your code and like the inner layer is the first one it sees
Starting point is 00:05:52 the second so if you the way he has it originally written it just fails it doesn't work um the second punch line is unless you've got a real good reason to use, um, auto spec, because auto spec would have caught this problem like right away. And, um, 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. Um, and, uh, 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.
Starting point is 00:06:34 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. 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 just don't use mocks.
Starting point is 00:07:03 Even he Brent mentions it in both articles, avoid, avoid using mocks. He mentions it in both articles. Avoid using mocks if you can. 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.
Starting point is 00:07:15 I love it. All right. What do we got next? Calvin, thoughts on mocking real quick before we move on? We are just diving into that and I don't do a lot of the 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
Starting point is 00:07:32 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 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, actually that was news to me. That's very interesting. All right.
Starting point is 00:07:52 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
Starting point is 00:08:04 for Linux and Mac mac os but wow this thing is cool um 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 exist 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 aliased 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.
Starting point is 00:08:47 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. It understands your git ignore. And the files that are considered hidden are the git ignored ones as well.
Starting point is 00:09:03 And it won't show you, even if you do like a hidden file listing it won't show you things like the dot es underscore store on mac os because that's in the git ignore so uh 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 it's the directory's hidden like it's 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,
Starting point is 00:09:33 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 an please dash dash 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 um the size in the human term so instead of like 101121171112 it would say that's 10.2 gigabytes
Starting point is 00:10:00 which is nice but it also shows you the get 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 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 tweet was people were like, how does it have custom icons? What magic is this? Because this will work over, like if I SSH into somewhere and install please on the server,
Starting point is 00:10:34 as long as my local terminal is set up correctly, this will work. And they're 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 is that I wish it would have
Starting point is 00:11:02 emulated more of the flags from standard LS so that it just kind of worked alike. I installed it, and the first thing I did was like, please dash AL, and I got like a 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 do these things. Another thing that's interesting, you can set up these uh these
Starting point is 00:11:26 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 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 on 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 so that is awesome i mean we need more we need more like fun stuff in our terminals as developers i i totally love this uh this is absolutely the way to get people hooked on using the terminal in the console yes Yes. And I was thinking about like server management, which we'll get to later, right, Calvin?
Starting point is 00:12:08 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. It's your 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
Starting point is 00:12:26 listing of files yeah 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 uh, more terminal stuff. Absolutely. Speaking of more terminal stuff, take it away. All right. So we over at Six Feet Up have been very focused on the developer experience. And so once a week we get together and talk about just we do a code review, but 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.
Starting point is 00:13:12 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 like my primary mode of operation is basically
Starting point is 00:13:35 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. Uh, it tuned for performance. And you may ask, well, why the heck would I want a GPU-enabled terminal? It's just showing me text. It's because I want the most performance possible out of my system when I'm using it. So I was going to give a quick little demo here of Kitty. This is actually using PLS. I see it. I have the right.
Starting point is 00:14:03 Is this Omai Posh also? What do you got for the... Oh, for the bullet train down there. and i'm there yeah i see it i have i have the right what is this oh my is this oh my posh also what do you got for the oh for the the bullet train down there so it's actually bullet train core uh it's not maintained anymore that's probably my next my next venture is going to be replacing that line with starship or something like yeah so exactly some new you know system for showing my awesome like prompt up there but 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 give you a quick example.
Starting point is 00:14:45 So if I run Kitty, it is, I love, but I love it. 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 gonna use iCat. I'm gonna just basically echo out a Slack emoji that we use for Python. Oops, oh, oh no.
Starting point is 00:15:03 Is this like gonna be like, total like demo guys, not, not being very kind to me now. I love that your, uh, your prompt has the Python version and stuff in there. That's great. Oh yeah. If you're in a specific like PyM area, it definitely shows up. Let me just, let me just like try it here. I had 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 do a quick look on an image.
Starting point is 00:15:33 I can actually quick look on any image I want. And one of the things I did want to show off, if I go back to the directory where I was at. For people who are listening, this looks like a full high-res image in the terminal based on a PNG. So I used ICAT, which is a kitten, full high-res image in the terminal 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 show even some coolers, because one of the features of Kitty is it's basically got a graphic subsystem in here.
Starting point is 00:15:55 And if I wanted to look at my markdown files, normally if I'd use BAT to look at my markdown for the readme that's in here, you get the kind of content highlighted markdown, kind of cool, not super great. But if I do MDCAT, which is KITI enabled, it actually leverages the KITI 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
Starting point is 00:16:30 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,
Starting point is 00:16:51 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 diffs, two different files. I can page through the different files and it shows me side by side diffs. Is that still in the terminal? That is still in the terminal. I did not leave my terminal.
Starting point is 00:17:15 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 shortcuts are super nice. One last thing. The diff just sold me. So yeah, you can split your windows, obviously,
Starting point is 00:17:31 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 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 owning.
Starting point is 00:17:51 Okay, I got a question. So I've always been confused about this whole windowing thing because I just opened another terminal. So- Oh, I see what your question is. I don't wanna open another terminal. I don't wanna reach for my mouse when when I have to go between terminal windows. So I'd rather have multiple tabs and then have splits.
Starting point is 00:18:10 And so I can have a paging going on in one window or another window. I can then edit these things, make them shorter or taller or split them in a different way. So I feel like just keeping my hands on the keyboard keeps me more productive as a developer as opposed to,
Starting point is 00:18:25 you know, 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 cool so i know we're not to the joke section yeah but you know the joke about how do you generate a random string put a new
Starting point is 00:18:49 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 or An 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.
Starting point is 00:19:14 It supports all the nerd fonts, all the color schemes. I've got, you know, there's a bunch of cool plugins for it. I've got a search plugin which searches back through your terminal. And so if I was, there's nothing in that specific one, but if i search through here and wanted to search backward it
Starting point is 00:19:29 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 nice so it's all built in plastic yeah now really cool also really cool is our new sponsor Fusion Auth thank you them for sponsoring this episode so let me just tell you
Starting point is 00:19:51 really quickly about them they're an authentication and authorization platform built for devs by devs it solves the problems of building
Starting point is 00:19:59 essential user security without adding the risk and distraction from your main app Fusion Auth has all the features you need need for great support at a price that won't break the bank. And you can either do self-hosting or you can get a fully managed solution running in
Starting point is 00:20:14 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 FusionAuth 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 slash FusionAuth or just click the link in your podcast player show notes and let them know you came from us.
Starting point is 00:20:41 I want that t-shirt. Thank you, FusionAuth. That's cool. I know. Yeah, you got to get a cool t-shirt, a cat slash, et cetera, slash power password.
Starting point is 00:20:49 Yeah. Very cool. Nice. I love when you get a cool t-shirt from our sponsors. All right. Well, Susan like cats. I know.
Starting point is 00:20:58 And kitties. I can tell that you're already a fan of kitties. Well, so I don't know if a 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,
Starting point is 00:21:23 but it's called futures and easy parallelization. And I was like, 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 or async IO. It's talking about
Starting point is 00:21:40 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 um this this example brings up a thread pool a thread pool, a thread pool executor, and then runs them all at the same time. Uh, does an executor submit, and it's just a small snippet of codes, just a handful of
Starting point is 00:22:13 lines. And then I tried this out. So this example actually, uh, is kind of boring. It's just doing, um, like a power X to the power of two, um, or X squared on a couple of things. I think that's what star star is, isn't it? Is that power of? I don't remember.
Starting point is 00:22:28 Yeah. X to the power of two. Yeah. X squared. X squared. So the other example seems a bit more down to earth. And that's, yes, on our screen, on the YouTube screen, it's the entire program here. Uh,
Starting point is 00:22:46 it's just, you're taking a few, a few websites and a couple of pages to go to and, um, and then actually just slurping those down with requests and grabbing something about them. And this example, just, uh, 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 time in here as just like a debug thing
Starting point is 00:23:18 and the example doesn't import time. So you have to 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 big data files that I'm looking for stuff on. We're grabbing error logs off of different systems.
Starting point is 00:23:44 And this would be a great example to just grab them all at the same time and pull them in. Yeah, this is nice. One thing that's cool about the futures you get back from the thread pool executor is you can say.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 the article kind of talks about that. Whereas on async IO, it throws an exception and says it's not done rather than just blocking. Oh, yeah. Yeah. And the article kind of talks about that.
Starting point is 00:24:07 It's one of the simplest things is you tell the executors, you call executors submit, and that gets the jobs ready. But that doesn't block. Those are, you can submit as many as you want. And then in the example, he's just using like future. dot result in a list comprehension. And that for each of those results, 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. Yeah, exactly.
Starting point is 00:24:42 If you block on the first one, it's not done. The second one might finish 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 async io too oh i've been deep in the async io world well it all feels natural to you and that's well 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, like maybe a DevOps person or something. They're not writing async programs, but they might have async needs or asynchronous needs
Starting point is 00:25:16 that can be solved with a simpler code. Yeah, this is very elegant, easy to understand. Yeah, nice article. Good one. All right. Well, I 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 episode. It is.
Starting point is 00:25:33 It's tool time. All right. So I did an episode on TalkPython 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.
Starting point is 00:25:51 So now, you know, 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.
Starting point is 00:26:14 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. Okay. So 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,
Starting point is 00:26:37 which does cost money. Just to be clear, this is 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, uh, basically, um, 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 like it'll show you this beautiful visual way of explaining it. And then you can dive into it. And if you click on it,
Starting point is 00:27:11 it'll tell you things like, okay, this is a nested loop. And on this part of the query, it took 152 milliseconds. You got 100 rows back. And then it actually describes the situation, why it's good or bad. So for example, it says you got five stars
Starting point is 00:27:26 because you discarded 1.3 million rows. That makes it faster, but you only got 3.2 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, okay, 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 101 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'd never seen it either. Now from the, from the interview, it sounded like it would recommend how you could change your
Starting point is 00:28:09 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 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, poor index efficiency,
Starting point is 00:28:29 disk operations. So like you've got to read too much off this to answer this question. Poor cache performance, excessive heap 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 yeah
Starting point is 00:28:53 anyway it is a paid tool but man if you could for 95 make your website 10 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's worth a lot, I think. 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, $500 an hour. I will absolutely come in there.
Starting point is 00:29:24 Yeah. And I have this new business, a 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, 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 nice that is super cool yeah all right calvin you got the last one all right last one up uh 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
Starting point is 00:30:02 for all those platforms this one doesn't support 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 IOS is being used, how much memory is being used, how much SWOT is being used. And bpyt top is kind of
Starting point is 00:30:25 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. I got sorry, little interruption there. But while I'm live here on the podcast, this is glances. It's kind of like more tech, texty kind of old school looking um but if you just pipx install and that's how i typically install these kinds of tools it will sorry about that it's all good yeah pipx is the pipx is the the homebrew oh man it's amazing on things right you know that's that's how you just pipx install bpytop if you don't have um pipx installed you should install pipxytop. If you don't have pipx installed,
Starting point is 00:31:06 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 of the, you can kind of see on here there's like um 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 the cpu or the
Starting point is 00:31:38 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 like task manager oh yeah or um 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 the network i 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 like 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
Starting point is 00:32:29 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,
Starting point is 00:32:55 every machine I log into for, you know, customers or production type stuff, if 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, 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 b by top was like the super powered version of glances interesting you've
Starting point is 00:33:19 moved over yeah the graphs are way better yeah um 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
Starting point is 00:33:51 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 uh speaking of beautiful alvaro it says b pie top has themes yes they use the dark gila theme yeah i love the fact that anything's got themes i can customize like you
Starting point is 00:34:19 know kitty or even b pie top or my whatever my ide. 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.
Starting point is 00:34:37 If you sit down and you're like, I am excited. Look how cool this is. Look how cool it is. 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.
Starting point is 00:34:46 Now, the only issue is when you sit down with someone who's like, they fire up TextEdit to like edit some text. You're like, what are you doing? Like, come on. Like, let me show you some cool tools.
Starting point is 00:34:56 Like, let me get you up to speed on here. Yeah, yeah. TextEdit being the notepad equivalent if you're not a Mac person. Yeah. That's, maybe it's a WordPad. You know, maybe it's a WordPad level. that's probably where which is worse i think that's worse than notepad because you're gonna get weird corrupted characters that you're not gonna know yeah oh man one of the
Starting point is 00:35:15 especially with um with working from home now a lot of people um 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.
Starting point is 00:35:34 Well, I hack on code. Yes. The original, the original, exactly. The original meaning of that word. Yeah.
Starting point is 00:35:44 Brian, time for some extras. I do have a big extra that i'm really excited about yes the book uh is um 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 um anyway so it's there's no longer a beta flag on it. It's not in beta anymore. So it's off to the printers. And then to celebrate it being officially released, there's a coupon code that we'll link to this page in the show notes, but it's a coupon code.
Starting point is 00:36:19 I don't know how long this is going to be good for, but this is for 40% off the e-book. So this is exciting. And I don 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 weeks so um yeah anyway that's uh that's one of my extras the other uh extra i wanted to bring up is uh pie camp spain is happening um april 15th through the 18th and man this looks fun um it's like actual camping i love the idea well like i i don't know if it's actual camping but there's uh um admission includes uh four days and three nights including accommodations and breakfast lunch and dinner
Starting point is 00:37:01 provided this is uh pretty amazing i know b. I see karaoke on that list too. Karaoke talks? Board games? Ping pong? This looks great. You have to give your talk in song form. Oh, man. No one would want to see me do that.
Starting point is 00:37:17 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.
Starting point is 00:37:31 Oh, I've got the, let me pull up the slide for it. You've got the screen if you want it. I do have the screen for it. I had even pre-planned for this to be ready to roll. So it is Python Web Conference time. This is our 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.
Starting point is 00:37:53 If you scroll down through here, there is just an 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 were doing five tracks across five days. So there's two app dev tracks, a culture track, a cloud track, and a PyData track.
Starting point is 00:38:21 So there is something for everybody. Get your tickets now. It is going to be a ton of fun. We will start getting things cranked up a Pi 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're 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 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
Starting point is 00:38:54 people in the speaker list have been here on the show. Yeah, you 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'm noticing a lot of these speakers from either this show or TalkPython or Test&Code. They've been, a lot of people have been on one of those. Yeah, a lot of friendly faces. A lot of friendly faces on here. And again, great, great group of people.
Starting point is 00:39:18 They're all super excited to participate in the conference. They're all super excited to hang out with everybody and 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 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.
Starting point is 00:39:45 Well, how about... No, I don't mean to cut you off, but I was just curious if Michael had any extras. You know that I do. All right, I got a couple. 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,
Starting point is 00:40:02 and I really enjoy working there. I love that 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,
Starting point is 00:40:24 I'm gonna cycle between them, like command tab, the alt tab equivalent impossible if it's the same app if i got one web browser set of tabs and another i want 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 uh map 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 just cycle between the last use window instead of last use app and there's just a the customizability of it is insane. Like it's truly crazy. And what does it cost?
Starting point is 00:41:07 It costs $14 a month. 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? I was really to say like some of the time you can use comprehensions of various types. That I 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
Starting point is 00:41:29 and a for loop. They're the same. Like, how could you even tell me that they're different? Well, one, import dis from dis import dis, dis like a symbol, and you'll see a big difference. But two, I put together an example that for 10 million times basically adds the numbers 1 to 10 million, even numbers 1 to 10 million to a list using a for loop and then using 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. So I'll link link into a very small gist there um i just my that people of mine if you're gonna do a loop at the very least don't do for i in length of something um that's c that's not python so yes please or or create a number uh count equal you know i equal zero while i less than this I plus plus on the inside, right?
Starting point is 00:42:29 Yeah. There's a lot of bad variations. Yeah, 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. they're yeah exactly programmers but 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 i use flask all the time all right how about you create a hello world view and run that um i 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. Alright, another thing, another similar little gist thing
Starting point is 00:43:07 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? We talked about the result and blocking and all how painful that is. So I came up with this little gist that
Starting point is 00:43:23 was working great in production, in dev. so this really simple thing you can just wrap up an async call and say uh run it it internally manages a little loop and it calls run i think so you got like a database uh async call you can just say um you know go to the 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. 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, micro WSGI was like shuffling around like the order of when stuff ran on different threads
Starting point is 00:44:06 and it was freaking out the event loop. And you get all these errors about like, this thing has become detached from its async IO 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
Starting point is 00:44:22 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 uh as part of this conversation maybe it works really well but it looks really bad uh bill jones um so from court, I believe, sent over a thing that said one of the problems with async IO is if it's already running and then you call a sync version, which internally happens to use the same pattern, it's going to crash and say it's already running.
Starting point is 00:44:57 Weird. So there's this thing called nest IO, which allows you to basically have re-entrancy. 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-continue on in the same loop. All right, those are all my extras.
Starting point is 00:45:17 I thought those were all a little fun. Nice. I can't believe combining threading and async IO in the same little sub modules. Brave. I did not get to that position willingly. Not at all. Like,
Starting point is 00:45:33 but everything I had tried, it didn't matter. And people say, Oh, you should use async IO 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
Starting point is 00:45:44 threading tricks. 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.
Starting point is 00:45:56 Always. Definitely. 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 asked 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, um,
Starting point is 00:46:29 void interact with humans. If is crazy robot equals true, kill humans else. Be nice to humans, but it's an assignment, not a quality. It's a single equals instead of a double equal. So end of the world has come because of that.
Starting point is 00:46:45 You've just decided to be a crazy killer robot. Crazy murdering robot. Yes, exactly. Anthony would save us from this cartoon apocalypse by saying this, remember your unit tests. Yeah, and beta testers. Why do we keep losing QA people? I just don't understand. do they go i don't know
Starting point is 00:47:08 just ship it to beta yeah um yeah exactly exactly segment your population ab test this stuff uh anyway no thanks nice but uh thank you calvin for coming on the show this time it was totally fun love it yeah absolutely brian thank you that was a good coming on the show this time. It was totally fun. Love it. Yeah, absolutely. Brian. Thank you. That was a good time. Always. See you later.
Starting point is 00:47:29 Yep. 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 nav bar. We're always on the lookout for sharing something cool.
Starting point is 00:47:49 If you want to join us for the live recording, just visit the website and click Livestream 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 Ocken, this is Michael Kennedy. Thank you for listening and sharing this podcast with your friends and colleagues.

There aren't comments yet for this episode. Click on any sentence in the transcript to leave a comment.