- Podcasts
- Python Bytes
- #401 We must replace uWSGI with something else
#401 We must replace uWSGI with something else
Python Bytes
- September 17, 2024
- 31 min
- Episode 401
About this episodeTopics covered in this episode: “We must replace uwsgi by something else” Let’s build and optimize a Rust extension for Python Fake…
- “We must replace uwsgi by something else”
- Let’s build and optimize a Rust extension for Python
- Fake recruiter coding tests target devs with malicious Python packages
- Monthly PSF Board Office Hours
- Extras
- Joke
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#401 We must replace uWSGI with something else
Oh, never mind. See people in wrestling. Or maybe we won't do it at all. I don't know. YouTube's good. Okay. And Michael even said to keep that quiet. But just, you know, sorry. I was pretty excited. All right. I know. Well, we'll try it out. I think, you know, reaching more people, letting them participate is great.
So, but that's not now yet. Now we have whiskey. Whiskey, anybody? This actually might make you want to drink this whiskey, uWSGI in particular. WSGI. As some people say it, web service gateway interface. The friend and sibling parent. I don't know what the relationship of ASCII, the async gateway interface.
Anyway, this is something I ran across. Just, I was doing some work with Granian. So Granian is the web server that powers Python bytes right now. And a couple other things, as you might imagine, and I was looking at it and it had a back reference. And one of the issues that was a feature I was asking about, namely worker restarting after certain amount of work gets done, things like that.
Why must we do this? Wait, let me see what's going on here. So this is somewhat news to me. The very opening here by, let's see, what is this? I wrote this. Regis Bimo wrote, uWSGI is now in maintenance mode. And sure enough, if you go over to read the docs, it says note, this project is in maintenance mode.
Only bug fixes and updates for new language APIs. Do not expect quick answers for GitHub issues or pull requests. Sorry about that. A big thanks to all users who have contributed over the last 15 years. That's awesome. However, I don't think that's awesome. It's awesome that they've been working on it for 15 years and people, it's had such a good run.
And anything that just listens on an open socket on the internet, especially stuff written in C should make you nervous. Right. It's just, it's there, for, for, whatever might go wrong. And so there's a couple of things going on here. One, it's kind of, it's not fully, fully abandoned, but it's nearly fully abandoned.
Right. And that's not great. The other is it, I don't believe it supports asynchronous programming. So if you want to do anything and async and await in your web apps, which is becoming increasingly popular, there's also not an option. So just for lots of reasons, it's probably time to find something else.
And so they listed four things, some of which I would not recommend, but maybe they're, maybe they're wrong about it. Gunicorn, which by the way, some people pronounce gunicorn, but Brian, what is their logo? It's a unicorn. And what color is it? Green. It's a green unicorn. I'm pretty sure he unicorn stands for green unicorn, not gunicorn.
So looking through, it says some people are suggesting engine X unit, which is, like a Python worker process that can run inside of engine X. That could be interesting. someone, this is how I found out about someone says, Hey, maybe we should look at, uh, Granian and Granian. And I've had, I've had, Giovanni, the guy who creates it on talk Python to talk about it.
It's written in rust. It's super stable in terms of its performance fluctuations. It's pretty nice. And so that's what we're using now before that it was Gunicorn. I think there's some good options, but the long and short of it is uWSGI is now in maintenance mode. And while that's not, you know, end of the line for it, I would start making plans to not be running on uWSGI.
Put it below there. That's, that's kind of our comment sections these days. Yeah. Yeah. Nice. Okay. All right. Over to you. Well, I was, interested, actually, I have a project where I was thinking about writing a little segment of it in rust, even though I don't know rust yet. but, but I was interested in the, the, a lot of places are, you know, optimizing little bits of their code with rust instead of C now.
I've got one algorithmic function that I want to speed up. And that's, I think that's a great place for maybe not building a package for the rest of the world to, to use, but internally for the internal tools, that's a great way to, to, to look at things. So his, his example is a, a thing of counting unique values and you could just count them.
He's gotten the exact count is using sets and, the length of a set, but everything in a set. But, but he says, if you've got 10 million items, it'll be in a set with 10 million items in it. So there's a space limit there. So, and then you take the length of that. so I'm in there, you know, you probably count things or something, but, the, is like, how do, how do we speed that up?
And one of the algorithms is a, it's called a very simple algorithm, from, I'm not going to try to pronounce that name. but he has a link to the algorithm that's getting an approximation of the answer, how approximately how many. And so he just implements that whole algorithm in Python and then, and then runs it and, and it, and then runs it against the exact count.
Yeah. That's pretty wild. It is. It's pretty close. and I remember reading about this algorithm recently also, but anyway, it's kind of a neat, neat example of, okay, let's try this algorithm out. And there's other algorithms for approximating uniqueness as well. comments later, but, he just took this one cause it's kind of a small algorithm.
So it kind of works. and so let's, he did a speed comparison and it's, it's significantly slower. It's, the exact count is point is 0.14 seconds and the approximation is 0.7 seven, eight seconds. So it's, it's a lot slower than the exact count. but it takes up tons less memory. So if you have a like memory constraint, that's important.
and also if you're just doing an example from a small count, but you have a huge set that you're really going to count, you want an approximation. So, so this is a great, a great setup for how do we make this faster in rust? And so he actually walks through all of the steps. Like you haven't done this before.
let's get mature in and Pio three and set up a project. he's, so he's even like, just mature in new rust counter prox project. and then, goes into it, looks at, looks at what the project set up already. It's got some cargo Toml files, pipe project Toml and a source file. and, and then he just does it right there and, and figures out how to install it.
You can already install it, even though there's nothing there in the example project, which is kind of cool. he did look into it. It needs, rust doesn't have a random in the example or the algorithm uses random. So, this is kind of neat too, is, is how do you, introduction of how do you add, uh, dependencies and it's cargo add Rand and that it adds a dependency to your project.
Like I don't want that much, but like twice as fast. I want it to be super fast. So yeah, he also goes into some optimization. So first, first off is link time optimization. It's just an ability. and since, since this is a rust application that you're going to not, you know, you, it's fine to take a little bit extra time in linking to make it faster runtime.
Go ahead and turn that on. And then, he was looking at the random number generator. there's a couple of ways to speed that up. One of them is to use the small random number generator. It's like less random, but you know, good enough. It's not cryptography. Yeah. And then, and then also there's, instead of storing in part of the algorithm, he's storing items.
And I just wouldn't really want an Apache plugin. I would kind of like a thing that's a little more dedicated, but yes, I agree. And then waitress is one of the few options available on windows based server platforms. Okay. That's interesting. The context of the GitHub issue I talked about before was a Docker image.
And so I'm pretty sure it was Linux. but yeah, I didn't know about the windows aspect there and I didn't point out like, well, what would I have picked? So reasonable options to Michael sound like Granian, which we're using uvicorn, which used to be a kind of dev thing. And you could plug it into Gina corn with uvicorn workers, but actually it's now its own standalone thing with worker management.
And so, so uvicorn is its own possible option. Now Hypercorn from Phillip Jones and court and then Gina corn with uvicorn workers for async stuff. So anyway, putting a bow on that one. Okay. So you have a few things you do instead. Yeah. I don't, I'm just using Granian right now, but all those would be good options.
They're a leading Python application performance monitoring tool, APM, that helps you identify and solve performance abnormalities faster and easier. Scout APM ties bottlenecks such as memory leaks, slow database queries, background jobs, and the dreaded N plus one queries that you can end up if you do lazy loading in your ORM.
And you'll love it because it's built for developers by developers. It makes it easy to get set up. Seriously, you can do it in less than four minutes. So that's awesome. And the best part is the pricing is straightforward. You only pay for the data that you use with no hidden overage fees or per seat pricing.
And I just learned this, Brian. They also have, they provide the pro version for free to all open source projects. So if you're an open source maintainer and you want to have Scout APM for that project, just shoot them a message or something on their pricing page about that. So you can start your free trial and get instant insights today.
Dear. Dear, that is so, why can't people be better? You know, some people just suck. So the item I want to talk about comes to us from reversing labs and pretty cool logo there with the reversed R for reversing labs, I got to say. And the title is fake recruiter coding tests target devs with malicious Python packages.
That's not ideal. And I don't know why we need to have the word Python packages in here. Just malicious Python code, because a lot of it comes from GitHub repositories, not IPI. So I don't know. I think kind of put the packages to the side. That's not germane to this, really. What is, is people are using recruiting tests.
So a lot of, this is something that I never encountered in my, yes, I never encountered this in my entire life. A take home exercise or something. It was interviews and it was live sort of code performances or whatever, I guess you would call them, but never take home. And that's just something that's becoming really popular for better or worse.
All right. So reversing labs found the VM connect campaign, which I don't really know much about continuing with malicious actors posing as recruiters using packages and the names of financial firms to lure developers. So that's pretty bad. What's happening here? So they've, this is not exclusive to Python.
It's happened through npm before and so on. And this seems to be tied to North Korea's Lazarus group, ATP group. That means bad stuff. You know, they're pretty, pretty skilled. But here's what happens. They found that people are getting these requests for coding tests and it says, here's your, here's your coding test.
And if you look at it, I think I can even zoom it here. Well, not really. It kind of zooms. Anyway, it says, here's a fully functional password manager in Python. Basically this, you can see some grammatical errors in there. You might, that might clue you off, but probably not. This is a fully functional password manager that possesses almost all of its features.
It's the running of this project that they delivered to you over GitHub or some other, they just sent you a thing to unzip and run that then downloads all the code, installs back doors, various other malware into your machine. And then you probably go on to finish the work and submit it and never hear back oddly.
Yeah. And then somebody is actually like finishing the assignment and not. Yes, I know. It's so sad. Sucks so much. Oh, that's terrible. Yeah. The analysis revealed that the direct parent of the detected malicious files is a Python PYC file. So that's how they obscure it as part of what they give you are PYC files, not Python source files.
So you can't really see inside them. Oh, and you, and you kind of think, oh, well, that's legitimate because it's a, because it's an interview. I, they're going to want to show me, show me the source code or something. Exactly. Yeah. It totally makes sense because yeah, if I saw this, well, then I would be able to, nope, your job is to have this opaque thing and write this one part.
But no, it's just the opaque part is a virus. Oh, that's so sucks. It totally does. Yeah. So I would, do you have recommendations? Well, I, let's hear yours first. Oh, I was thinking that, so, I've, both, taken, interviews like this, um, coding exercises and given them, but in, in, let's see, most of the times I've only given them in text form.
So for example, I think VS Code has, you know, code.dev. Is that right? I can't remember what it was the, like if you open up GitHub and just press dot, whatever happens there, maybe you could do it there. Yeah. maybe not. probably what I would actually do is I would fire up a virtual machine that has snapshotting capabilities.
And by snapshot, I mean like save how it is now on the, on the disc and then make a differencing disc. And then when you're done with the project, just throw away the snapshot, the different reset to the snapshot. Right. So that's long as it's, you're not afraid of it being potentially on your network.
Right. But if it's in a VM, it's probably pretty safe. Right. And then also you could go over to Azure and get a windows machine, windows VM that you can remote desktop into. That's a full windows machine in the desktop, in the cloud as a desktop, you log into right there and just throw away the virtual machine.
Cause you know, then it's not even on your network. Right. Yeah. I think, and as much as I like using my own editor, I think that I'm, I think that people that are giving coding exercises really should use a platform, because it's just more fair for everybody. The, and the, even our friends at PyBytes have their own interview platform that you can do.
You can do their little things. Matt agrees with you. Plus one for coding platforms. Yeah. All right. Okay. So folks be, just be on the lookout and be careful out there. It's the internet. Well, is it my turn? I think so. let's, let's talk about office hours. so the PSF has announced that the PSF board is having office hours, which is kind of cool.
They're going to do it monthly. So if you have a question, if you, what do they say? greetings Pythonista. I'm not going to read all of this, but the PSF, is going to open up, office hours and monthly, the office hours will be a session, be sessions where you can share with us how we can help your community and express your perspectives and provide feedback to the PSF.
And hopefully everybody will be nice, but had an issue with people being nice. So try to be nice. then also, the joining of the office hours, there's, there's, we missed the first one that was September 10, but there's one October 8th. And then, and then there's, you know, there's a list here we've got.
Well, I'll just put the list in the show notes. Also, what do you, what are they going to talk about? Well, they might have, they might have a topic, but, they also might not. So it says that you can bring up, I can't remember where, where it said this, but you can bring up, there'll either be a topic, but if there's not a topic, you can bring up something that's Python related or something that the board might be able to help you with.
So that's really cool. I love the accessibility that, that, that people have access to. Yeah. I think it's kind of cool. I think it's kind of like, it kind of reminds me of, you know, you can, I've never gone, but my, my little local community that I live in, I can go watch the, the, the, the city board meetings if I wanted to, I don't, I don't do that, but I like that it's possible that I can.
Big news is our courses, mine, yours, and our friends are on humble bundle for a couple of weeks. So if you want to get what I think is probably a ridiculous deal, like $1,882 worth of content for $25. Check it out. One of the things that's unique about humble bundle, if you're not familiar with it and partly why we're participating is a lot of money goes to charity right now.
The, I'm including the, both the new Hello pytest course and, and the complete pytest course and the pytest course on your side. I know that's kind of a lot of pytest, but I kind of think about it a lot. so a lot of exciting people already joining, and I'm getting some great questions in the community forum.
so that's really good. Even some great feedback. yeah, it's awesome. So I'm pretty excited about this. All right. So this is one among many extras, but do check that out if this sounds interesting to you. It's a lot of stuff and it's for a good cause. Okay. Next, I believe we've talked about the Django Not program before, which is super cool.
And I think it's a really cool program. Free eight week group mentoring program. Cool. Yeah. So if you're a fan of Django, you want to get better at open source. Here we go. like I said, a link to this, two more things real quick. One planned and one, a surprise alt tab. If you're on windows, alt tab is the way you switch between apps on macOS.
If you switch to macOS, things get weird. Like command tab seems like the alt tab, but command tab switches between applications, not between windows. So for example, if there's like a, Hey, there's an update available for your app. And then it goes behind another window. There may be no way to keyboard over to it.
You might have to hit control down and then find it because it doesn't register as like a top level application, but it's there. And like, you want to switch between two windows and web browser. I know there's command tab, but that, or sorry, command tilde, but that just cycles. That doesn't give you a list.
So alt tab is a free open source thing for macOS with a ridiculous amount of options that has a super cool UI for switching between windows, not applications. And like I said, it's open source, but also it doesn't take over the typical commands. So it's an either or whatever you feel like hitting while you're working on Mac.
What do you think, Brian? Cool. Yeah, actually, I don't, I never even tried any of this stuff. I just usually don't have very much open or I have no idea how to find my stuff. Yeah. But if you look over on GitHub, it's got 10,000, almost 11,000 stars. It's pretty neat. Yeah. So anyway, people can check that out if they want.
And this is the prize. This was not true when I hit, when we logged in to hit record today. However, since then, the macOS Sequoia, the new version of macOS is now out. Now, if you go to the website, apple.com slash macOS, it says it's in a preview. But if you go to a system settings, it says, would you like to install it?
Unclear. Okay. Let's give it a strong maybe. Well, I'm going to try to make sure to be there. Yeah, that'll be nice. I love PyCascades. Okay. So that's my first. And that's in February. So last week we talked about all the uv Python stuff being super cool. But we mentioned that you can't do Python 3.13.
Well, you can now. So Python 3.13 is now available for virtual environments and for anything with uv. So uv supports Python 13, but it does not subvert. If the next question is, can I do the other one? Free-threaded. Can we do through free-threaded? No, not yet. But hey, I think it's great to just support the normal one so that people can get their stuff in.
