Latest / Talk Python To Me / #58: Create better Python programs with concurrency, libraries, and patterns
Transcript
- 0:00What do you focus on once you've learned the core concepts of the Python programming language
- 0:04and ecosystem? Obviously, knowing a few fundamental packages in your space is critical.
- 0:08So if you're a web developer, you should probably know Flask or Pyramid and SQLAlchemy really well.
- 0:13If you're a data scientist, import pandas, numpy, matplotlib need to be something you type often
- 0:19and intuitively. But then what? Well, I have a few topics for you. This week, you'll meet Mark
- 0:24Summerfield, a prolific author of many Python books. We spend our time digging into the ideas
- 0:29behind his book, Python in Practice, Create Better Programs Using Concurrency, Libraries,
- 0:34and Patterns. What I really like about these topics is that they have a long shelf life.
- 0:38You'll find them relevant over time, even as frameworks come and go.
- 0:42This is Talk Python To Me, episode 58, recorded May 4th, 2016.
- 0:59Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the
- 1:17ecosystem, and the personalities. This is your host, Michael Kennedy. Follow me on Twitter,
- 1:21where I'm @mkennedy. Keep up with the show and listen to past episodes at talkpython.fm
- 1:26and follow the show on Twitter via at Talk Python. This episode is brought to you by Hired and SnapCI.
- 1:33Thank them for supporting the show on Twitter via at Hired underscore HQ and at Snap underscore CI.
- 1:41Hey, everyone. A couple things to share with you. First, we'll be giving away an electronic copy of Mark's book this week.
- 1:46As always, just be registered as a friend of the show on talkpython.fm. I'll pick a winner later in the week.
- 1:51Next, I had the honor to spend an hour with Cecil Phillip and Richie Rump on their laid-back,
- 1:57technical but casual podcast, Away from the Keyboard.
- 1:59I really enjoyed the conversation, and I think you'll like their podcast, too.
- 2:03Give them a listen at awayfromthekeyboard.com.
- 2:07Finally, those of you taking my Python Jumpstart by Building 10 Apps course,
- 2:10I have a few improvements for you.
- 2:12I added transcripts to the player, the website, and the GitHub repository,
- 2:16as well as added some activity tracking across devices so you know which lectures you've watched.
- 2:21I hope you find these additions useful.
- 2:22Now, let's chat with Mark.
- 2:24Mark, welcome to the show.
- 2:26Oh, thank you very much. I'm glad to be on it.
- 2:28Yeah, I'm super excited to talk about all these great books you've written,
- 2:31and one of them in particular really caught my attention, called Python in Practice,
- 2:36Create Better Programs Using Concurrency, Libraries, and Patterns.
- 2:40And that just really speaks to me on some of the most important parts of
- 2:45sort of design pattern and improving your overall skill,
- 2:48not just focused on libraries, like Flask or something.
- 2:51Yeah, sure.
- 2:53One of the motivations for writing that particular book was
- 2:56I wanted to write something for people who were already comfortable writing Python,
- 3:02but showing more of the high-level things you could do with Python.
- 3:06You know, if you wanted, for example, to do really low-level networking with TCPIP,
- 3:12you can do that in Python.
- 3:14It's got the libraries.
- 3:15All the facilities are there.
- 3:17But if what you're more interested in is application programming,
- 3:20you might not want to go so low-level.
- 3:23And Python, either built-in or in third-party libraries,
- 3:26has wonderful facilities for doing high-level stuff,
- 3:30whether it's networking, concurrency, and GUIs, and things like that.
- 3:34So I wanted to look at some of the facilities that are available,
- 3:38both built-in and third-party,
- 3:40that allow you to do some fantastic things with Python
- 3:44without having to get right down into some nitty-gritty details.
- 3:47Yeah, that's beautiful.
- 3:49I find that when people are new to Python,
- 3:52and this includes myself when I'm working in some area that I haven't worked in a lot,
- 3:56I'll not realize there's some really simple thing that I can use.
- 4:02And I think it's really great.
- 4:04There's a lot of those little tips and tricks in your book.
- 4:06But before we get into the details of your book,
- 4:08let's start at the beginning.
- 4:09Sure.
- 4:10How did you get into programming in Python?
- 4:11I started programming on paper in the late 70s.
- 4:17I started reading computer magazines.
- 4:18I taught myself basic purely off the magazines.
- 4:21And I wrote my code on paper, and I executed it on paper.
- 4:25Then eventually, I bought a home computer.
- 4:29I don't know if your listeners will remember what they are,
- 4:31but they were things before PCs.
- 4:32Very limited, but quite a lot of fun.
- 4:35And eventually, I went on to do a computer science degree, which I absolutely loved.
- 4:42And that gave me a lot of the sort of theoretical background.
- 4:45And then I just went into software development.
- 4:48And I'd been doing that for quite a few years when I bumped into someone who suggested trying Python.
- 4:54And I borrowed a book from a colleague, a fellow developer on Python.
- 4:59And I hated the book.
- 5:00And that put me off Python for about a year.
- 5:03And that was one of the motivations for writing my first Python book,
- 5:07was to write one that would actually encourage people to use it.
- 5:10But once I started using it, within a year, all of my utility programs and tools that I use for my daily work,
- 5:18they were in Python, because I just loved it.
- 5:22So that was around 1999.
- 5:26And now, everything I do, the first choice language is always Python.
- 5:30Yeah, the Python ecosystem and, frankly, the language is fairly different from the late 90s today.
- 5:36Oh, massively different.
- 5:38I mean, I actually didn't like the indentation at first.
- 5:41That took me like 48 hours before it really clicked.
- 5:45Wow, no braces.
- 5:47I just don't have to bother.
- 5:48And that was really nice.
- 5:50And also, of course, it forces your code to be quite neat in the first place.
- 5:54It doesn't, of course, make you use good variable names and things like that.
- 5:58You have to learn that separately.
- 6:00But that applies to any language.
- 6:02But I really liked Python pretty well from the get-go.
- 6:06Yeah, so did I.
- 6:07I think the indentation does catch a lot of people off guard.
- 6:11And to me, it's kind of like good science fiction.
- 6:14You have to sort of take this moment, the suspension of disbelief.
- 6:18Like, just imagine for a minute this white space concept is a good idea and work with it for a week.
- 6:25And then it just dawns on you, like, wow, this really is a good idea.
- 6:28Like, I went back to working in some C-based languages right after I sort of learned Python and started working in it.
- 6:35And the white space was a shock to me at first.
- 6:38But what was even a bigger shock was these C-based languages that I loved.
- 6:43I all of a sudden hated all the parentheses, the curly braces, the semicolons.
- 6:47And that was such a surprise to me that I felt that way.
- 6:50But it was within a week.
- 6:52It was just completely over the semicolon.
- 6:53Sure.
- 6:54And of course, there's no dangling else problem that you can get in C or C++.
- 6:59You know, if you've got an else with the correct indentation, you know what's going to be executed.
- 7:04You're not going to get caught because you hadn't put in braces, you know?
- 7:07Yeah, absolutely.
- 7:08Yeah.
- 7:09It really works for me.
- 7:10And Python, the language.
- 7:12Okay.
- 7:13It's Turing complete.
- 7:14And so is Perl.
- 7:14And so is C++ and Java and all of these languages.
- 7:17So you can do anything in one of them that you can do in the other.
- 7:21So why choose one particular language rather than another?
- 7:25And I think part of that is, well, what's the libraries and ecosystem like?
- 7:30And part of it is what fits the way you think best.
- 7:33And in my case, it happened to be Python that works.
- 7:36But, you know, I wouldn't argue against someone who preferred some other language if that suited them.
- 7:41Yeah, absolutely.
- 7:41But for me, Python is a great language.
- 7:44And particularly Python 3.
- 7:46I started using that from the first alpha.
- 7:49I'd ported everything from Python 2 to Python 3 right at that stage.
- 7:54And I think it's excellent.
- 7:55Yeah.
- 7:55You know, maybe that's a good segue to sort of taking a survey of the books that you've written.
- 7:59Because you've written many books.
- 8:01Is something, how many, around eight, seven?
- 8:05Depends whether you count second editions.
- 8:07Without second editions, it's seven.
- 8:09And with them, it's nine.
- 8:10Okay, excellent.
- 8:11Yeah.
- 8:12And one of them you wrote is a pretty sizable
- 8:15Python 3 book, right?
- 8:17Yes.
- 8:17That's Programming in Python 3.
- 8:19Yeah.
- 8:20That book is really aimed at people who can program in something or other.
- 8:25And it's to port them over to Python 3.
- 8:27But it should also work for people.
- 8:29And the something or other could be Python 2.
- 8:32Right, right.
- 8:34So that's who it's aimed for.
- 8:35It's not aimed at beginners.
- 8:36The subtitle was poorly chosen by me.
- 8:40A complete introduction to the Python language.
- 8:43Sometimes people think that introduction means it's introductory, which wasn't the intended intention.
- 8:49It was just, it's introducing everything that Python 3's got that you're going to use in normal, maintainable programming.
- 8:57The only things I don't tend to cover in my books are things that I think are dangerous and obscure.
- 9:03So, for example, in Python, you can disassemble Python bytecode, rewrite it, and put it back.
- 9:09And that's brilliant.
- 9:10But I wouldn't ever cover that in my books because I wanted to cover stuff that people can maintain.
- 9:15Understand that it runs.
- 9:18That's right.
- 9:18Absolutely.
- 9:19Absolutely.
- 9:19Maintainability and understandability are really important to me because, in my experience, you live with code for quite a long time.
- 9:27You know, literally years.
- 9:29So you don't want to torture yourself when you have to go back and fix something or do a modification to something.
- 9:37And it's been a few years since you've seen that code.
- 9:40Yeah.
- 9:40Oh, absolutely.
- 9:41So maybe tell us some of the other books that you wrote.
- 9:45Okay.
- 9:45You've got some interesting topics there.
- 9:47I think the first one I wrote concerning Python is Rapid GUI Programming with Python and Qt, which is about PyCute programming with PyCute 4.
- 9:56Although the book is – I mean, I've updated the examples for PySide as well.
- 10:01I really like the Qt GUI toolkit.
- 10:05I like cross-platform GUI programming.
- 10:08And that book, the first part of it is actually a very brief introduction to Python programming itself.
- 10:15And I was quite pleased.
- 10:17I had very good feedback on that.
- 10:18Many people said, well, I already knew Python, but I read the introduction because, well, I bought the book.
- 10:24And I still learned things from it.
- 10:26So I was glad about that.
- 10:27And Qt itself, I think, is good.
- 10:30I know that it's very fashionable, you know, mobile programming and web programming and things like that.
- 10:35And they're great.
- 10:36But I personally love desktop programming and desktop GUI applications.
- 10:42So it was an expression of something that I was really interested in and really enjoyed doing.
- 10:46Yeah, that's great.
- 10:47I agree with you that desktop apps are really – they don't get enough love, you know, because mobile is a super flashy thing.
- 10:55I actually spend most of my time writing web apps.
- 10:57But I do very much appreciate a good desktop app.
- 11:01And I think Qt is one of those frameworks that is cross-platform but doesn't feel cross-platform as a user.
- 11:07You're not like, oh, yeah, this button and this UI completely looks foreign.
- 11:12But it technically is a UI, right?
- 11:14Absolutely.
- 11:15Yeah.
- 11:15I mean, it really does – they really do well with native look and feel, even though they're not using native widgets, unlike, say, WXPython, which does.
- 11:23They emulate it all.
- 11:25But they do it very well.
- 11:26And some of their stuff on Windows is faster than native.
- 11:29Wow.
- 11:30The way that it's implemented.
- 11:32Because they're not – when they create a window, they're not creating all those widgets, which you would do using a normal Windows toolkit.
- 11:40They just basically create an image.
- 11:43Right, right.
- 11:44So it's much, much cheaper and much faster in terms of resources.
- 11:47So, yeah, I love that toolkit.
- 11:49And that's how I'm earning my living now because I'm earning my living writing on the back of commercial Python applications for desktop users.
- 12:00So they're written in Python, Python 3, PySidem Qt.
- 12:04Oh, wonderful.
- 12:05And do you ship those with something like CX Freeze to sort of package them up or was it PyToApp?
- 12:11That's exactly right.
- 12:12No, I use CX Freeze.
- 12:14And so, yeah, they're quite a big download because the Qt libraries are all in the bundle.
- 12:18And people can download them, try them, and, you know, hopefully buy them.
- 12:26Yeah, wonderful.
- 12:28And that seems to have worked for the last couple of years quite nicely.
- 12:31Yeah, okay.
- 12:32Fantastic.
- 12:33Yeah, that's a really cool story.
- 12:34It is possible to earn a living with Python not doing web programming.
- 12:38I mean, obviously, you can earn good money doing web programming as well.
- 12:42Right, of course.
- 12:43Or data science.
- 12:44Those are the two most common ones.
- 12:46Oh, absolutely.
- 12:46Yeah.
- 12:47Yeah, absolutely.
- 12:48So you also have some books on Go and C++.
- 12:52Oh, I've got a Go book.
- 12:53I did that because I was just really interested in Go.
- 12:57I think Go and Rust are both sort of new languages that I am interested in.
- 13:02And I like the simplicity of Go.
- 13:05And I'm also interested in concurrency.
- 13:08And so I started to learn the language.
- 13:12And I thought, yeah, I can write something better than what's available on this language.
- 13:17But one of the authors of Go has come out with a book on Go now.
- 13:22So I should think that will kill mine.
- 13:25You never know.
- 13:27You never know.
- 13:28I mean, well, I still think mine's a good book, actually.
- 13:30But there we are.
- 13:32In terms of C++, I have written a few.
- 13:36But they're all C++ with Q.
- 13:38So I co-wrote with Jasmine Blanchett, C++ GUI programming with Q3 and then with Q4.
- 13:46And then I did a solo one, advanced Q programming.
- 13:49Okay.
- 13:50But again, they're all C++.
- 13:52I still use them for PiSide programming, you know, to remind myself how to do things.
- 13:58And I actually use the C++ docs rather than the PiSide docs.
- 14:02So, you know, I can translate easily enough.
- 14:05Yeah, they're a little more definitive, maybe.
- 14:07Yeah.
- 14:07I am frustrated with C++.
- 14:10I mean, C++11 was like a huge step forward.
- 14:13But they just didn't deprecate enough as far as I'm concerned.
- 14:16So it's getting too big.
- 14:18And I think it's quite hard to write that language in a maintainable way now.
- 14:23Yeah, that language is just ever-growing.
- 14:26And it wasn't all that simple in the beginning.
- 14:28No.
- 14:29I have another question about Qt.
- 14:31I definitely want to get to the topics of your books.
- 14:33Sure.
- 14:33Given your background there.
- 14:34I just saw, when was this, back in mid-April, there was an announcement saying we're bringing
- 14:42PiSide back to the Qt project.
- 14:44That's right.
- 14:45I'm really delighted.
- 14:47Fantastic.
- 14:48It's going to be PiSide for Qt 5.
- 14:51Now, you can use PiQt with Qt 5.
- 14:54But PiSide has been Qt 4 only so far.
- 14:57But they're actually putting money behind it and investing in it.
- 15:00So PiSide 2 will be for Qt 5.
- 15:04And I'm really looking forward to that.
- 15:06Yeah.
- 15:07So am I.
- 15:07Do you know the time frame on when that kind of stuff will be out?
- 15:10They're doing the development in the open.
- 15:11I think there's like a GitHub or some equivalent of that.
- 15:14So you can look at it.
- 15:16But I would guess it's going to be, I think we'd be lucky to see by the end of the year
- 15:22something that's usable.
- 15:23Right.
- 15:24Because it's not a simple job.
- 15:26Yeah.
- 15:26There's a pretty big break from Qt 4 to Qt 5.
- 15:28Not so much the Qt side of it.
- 15:30I don't think that's the hard side.
- 15:32As you know, programmers, we love reinventing things.
- 15:37And when they did PiSide, they invented a new way of doing bindings.
- 15:42And I think that hasn't proven to be quite as maintainable and flexible as they'd hoped.
- 15:48So I think that's where they're going to have to do quite a lot of work, getting that to
- 15:51work with Qt 5 and the new C++.
- 15:54Right.
- 15:54Okay.
- 15:55Yeah.
- 15:55So it's more with the PiSide version than it is the Qt itself.
- 15:59Got it.
- 16:00I think so.
- 16:01I think so.
- 16:02Yeah.
- 16:02All right.
- 16:02Excellent.
- 16:03So I know there's a lot of interest in GUI apps from a Python perspective.
- 16:09And maybe another time we can dig into Qt even more.
- 16:12But let's talk a little bit about creating better Python apps.
- 16:15Okay.
- 16:15What was the motivation for writing this book?
- 16:18I mean, you said you aimed it at people who were in the middle, but you gave it four themes.
- 16:23You said, I'm going to cover sort of these general themes of code elegance, improving speed
- 16:28with concurrency, networking and graphics.
- 16:30How did you come to that collection?
- 16:32Well, graphics, because I just love GUI programming.
- 16:35So that had to go in because it's something I love.
- 16:38I also, with networking, I've done a fair bit of network programming, but I'm not a low-level
- 16:44person.
- 16:45I like my networking to be as easy as possible.
- 16:49And I wanted people to be aware that you can do networking really easily with Python without
- 16:54having to go down, you know, to low-level stuff and do it in a reliable and pleasant way.
- 17:00And I cover two approaches.
- 17:03One is XMLRPC.
- 17:04And I cover that because it's built, it's in the standard library.
- 17:08And it works really easily.
- 17:11So it's really nice.
- 17:13And the other one I cover is a third-party one called RPYC.
- 17:17There's another one called Pyro, which is also widely used.
- 17:23And I could have gone with either of those.
- 17:25And the advantage of RPYC or Pyro is that they can be Python-specific.
- 17:30So you can get better performance, whereas XMLRPC is general.
- 17:35So it's not got quite as good the performance, but it has the advantage that you can write a
- 17:41client and or server using XMLRPC.
- 17:44And it'll talk to anything else that uses the XMLRPC protocol.
- 17:49So that's very nice for interoperability.
- 17:52And they're high-level.
- 17:54So all of the detail and, you know, timeouts and all of the issues that can arise in networking
- 18:00is just neatly controlled and wrapped up.
- 18:02And, OK, you get exceptions and things like that.
- 18:04You know, all normal Python stuff.
- 18:07So you don't have to worry about the details.
- 18:08Yeah, it makes a lot of sense.
- 18:10So I want people to be aware of that, that these kind of facilities exist.
- 18:14You can basically write a wide range of different types of networking apps in Python, right?
- 18:20You can go all the way down to the raw sockets with Byte.
- 18:23I just talked with Mahmoud Hashemi from PayPal.
- 18:26And those guys are writing services that take over a billion requests a day.
- 18:30Wow.
- 18:31They're doing network programming in Python, but down below the HTTP level.
- 18:36Wow.
- 18:36And these custom APIs.
- 18:38And then you can, of course, go up higher, right?
- 18:40Like XML RPC or maybe REST service with requests, things like that, right?
- 18:45Absolutely.
- 18:47And it's the high level stuff that I was more interested in.
- 18:49And I think that's because at heart, I'm an applications programmer.
- 18:54And that means I know about the subjects of my application, but I don't necessarily have the
- 19:00expertise in particular areas that the application needs.
- 19:05And so for that, I want high level libraries that give me the functionality that are created
- 19:10by experts in those fields.
- 19:11So I get the best of both worlds.
- 19:13I get the functionality I need by, you know, excellent people who've developed it without
- 19:19actually having to learn all that stuff myself.
- 19:21Yeah, absolutely.
- 19:22I think the right way to start is start simple and then, you know, then go do crazy network
- 19:27stuff if you need to improve the performance.
- 19:29But generally, you don't have a performance problem.
- 19:32No, no.
- 19:33And that actually brings us nicely to concurrency.
- 19:36Python, you know, people say, oh, is Python slower?
- 19:40Python can't do concurrency.
- 19:42And I really wanted to address those issues because how slow is Python really?
- 19:47Well, I developed a program in C++ that was very CPU intensive.
- 19:52And I rewrote that program in Python and it was 50% slower.
- 19:57And I think that's not bad going from C++ to an interpreted language, a bytecode interpreted
- 20:04language.
- 20:05But of course, I then made it concurrent.
- 20:08And you could make it concurrent in C++, but it's much easier.
- 20:12They're doing that in Python.
- 20:13And so on a dual core machine, suddenly it was as fast as C++.
- 20:19Give it more cores.
- 20:20And it was faster than the C++.
- 20:22So even though baseline, yeah, it's 50% slower on real hardware using concurrency, it was much
- 20:29faster.
- 20:30And that's really what the user is going to care about.
- 20:31And that's really what the user is going to care about.
- 20:33You know, on my hardware is this thing running fast.
- 20:35Right.
- 20:36And of course, it's much more maintainable.
- 20:38I mean, doing concurrency in Python is so much easier than in most other languages.
- 20:43Yeah.
- 20:43And I think specifically around concurrency, it's easy to get yourself into a situation where
- 20:50you've been very clever and you've thought really hard about the algorithms and the way
- 20:55it works.
- 20:56And you've kind of written something just at the limit of your understanding.
- 21:00Like you totally understood what you did, but it's at the very edge.
- 21:04But of course, understanding multithreaded code, debugging it is harder than writing it.
- 21:09And so maybe it's like, you know, you've sort of gone a little too far.
- 21:13You're like, okay, I could write this, but I don't really understand how to fix it when it
- 21:17goes wrong.
- 21:17Yeah.
- 21:18And that is a real problem with concurrency.
- 21:20In some languages, you're stuck because the concurrency facilities, they offer pretty basic.
- 21:27So they don't make it easy.
- 21:29But Python offers higher level concurrent approaches to concurrency as well as low level.
- 21:34For example, you've got the concurrent futures module, which makes it much easier to create
- 21:42either separate threads or separate processes where Python takes care of lots of the low level
- 21:47details.
- 22:17Within the first week, and there are no obligations ever.
- 22:20Sounds awesome, doesn't it?
- 22:21Well, did I mention the signing bonus?
- 22:23Everyone who accepts a job from Hired gets a $1,000 signing bonus.
- 22:27And as Talk Python listeners, it gets way sweeter.
- 22:29Use the link Hired.com slash Talk Python To Me and Hired will double the signing bonus to $2,000.
- 22:35Opportunity's knocking.
- 22:37Visit Hired.com slash Talk Python To Me and answer the call.
- 22:45I think you really put this together quite nicely in terms of sort of breaking out the different
- 22:50types of concurrency.
- 22:52And it helps you understand if you sort of think, okay, well, what are the types of concurrency?
- 22:56What type of problem am I solving?
- 22:58Then you have a pretty good recommendation for if it's this type of problem, solve it this
- 23:03way.
- 23:04And so you said there were three types.
- 23:05You called them threaded concurrency, process-based concurrency, and then concurrent weighting.
- 23:10Yeah, yeah.
- 23:11Basically, if you're doing CPU-intensive work, then using threading in Python is not going to
- 23:17help because of the global interpreter lock.
- 23:21So if it's CPU-intensive and you need concurrency, then you need to use a different method.
- 23:26And Python offers, for example, multi-processing, where you can split your work over multiple
- 23:32processes rather than multiple threads.
- 23:34And each of those has its own separate interpreter lock so that they don't interfere with each
- 23:40other.
- 23:41Right.
- 23:41But I think the key to getting real performance from concurrency is to avoid sharing insofar as
- 23:49you can.
- 23:50And that means either you don't need to share in the first place, or if you've got data that
- 23:56needs to be looked at by your multiple threads or multiple processes, then it may be cheaper
- 24:01to copy that data rather than have them share some kind of locking to look at it.
- 24:07Right.
- 24:07And that's a mistake I think a lot of people make is they see the way that their program is
- 24:13working now.
- 24:14They've got some shared...
- 24:15They've got a pointer they're passing to two methods or whatever, two parts of the
- 24:18algorithm.
- 24:19And they're saying, well, this part's going to work on this part of the memory and this
- 24:22one's going to work over here.
- 24:23And so they think, well, when I parallelize this, this is shared memory access.
- 24:28And of course, you have to take a lock or somehow serialize access to that data.
- 24:33And it's easy to forget that, you know, if that's like a meg or even maybe 50 megs of
- 24:39data, it might be so much easier both for you and advantageous for performance to just say
- 24:45copy.
- 24:45Make a copy and just pass it over and then correlate the differences later.
- 24:49Absolutely.
- 24:50The other possibility is to share the data without copying, which is fine if you never write to
- 24:56it.
- 24:57So if you've got data where you're just reading in information like a log or some data
- 25:02stream, and you're never changing the information you're reading, you might be producing new output,
- 25:08but that's separate.
- 25:09So if the stuff you're reading, you can read that from a shared data structure as long as
- 25:14you read.
- 25:14And that's not going to be a problem.
- 25:16It's only when you're going to start writing that sharing becomes an issue.
- 25:21And then you've got problems if you don't lock.
- 25:24But the best way is still don't lock.
- 25:27The best way if you're writing data is write or save the data in separate chunks and gather
- 25:33it together at the end.
- 25:34That will often be less error prone and faster.
- 25:38Yeah, absolutely.
- 25:39But of course, sometimes there isn't a choice.
- 25:41Sometimes you do need to lock.
- 25:43And then that's when it becomes quite difficult to reason about because you've got to be clear
- 25:51when you need to lock and when you need to unlock and all the rest of it.
- 25:55And that's where the difficulty comes in.
- 25:57But if you can avoid having to lock, then you can get good performance without problems.
- 26:03Absolutely.
- 26:06And there's some of the data structures in the newer versions of Python that sort of solve
- 26:13that problem for you.
- 26:14And so we'll talk those a little bit.
- 26:16But when you said copy data, one way to say copy a data structure, like obviously you can't
- 26:22just pass the pointer over or get another variable and point to the same thing, right?
- 26:27Because it's a pass by reference, not pass by value type of semantics.
- 26:30So there's actually a copy module in the standard library, right?
- 26:34Yeah.
- 26:35And basically, what I would contend is this.
- 26:38If you use copy.deepcopy in a non-concurrent program, then there's almost certainly something
- 26:46wrong with your logic.
- 26:47But if you're using a concurrent programming, then it may well be the right solution for you.
- 26:54Because deep copying can be expensive if you're using like nested data structures, like dictionaries
- 26:59with dictionaries and things that are quite large, for example.
- 27:02But nonetheless, it may be the right tradeoff.
- 27:05Of course, the only way you're going to know for sure is to profile and actually time things.
- 27:10Because that's the other sort of big issue, isn't it?
- 27:13That, you know, we have an intuitive feeling this will be fast or that will be slow.
- 27:17But unless you back it up with numbers, you could be optimizing something that makes no
- 27:22difference whatsoever.
- 27:24Yeah, you had some really interesting points there that I thought were both interesting and
- 27:29good advice.
- 27:30One was, if you're going to write a concurrent program, write the non-concurrent serial single
- 27:37threaded version.
- 27:38Absolutely.
- 27:39first, if you can, and then use that as the baseline for your future work, right?
- 27:44I mean, one of my commercial programs, it does its work using concurrency.
- 27:49It's written in Python and it's concurrent.
- 27:50But I have two modules that do the processing.
- 27:55And one uses concurrency and one doesn't.
- 27:58And the tests, I have to make sure they produce exactly the same results.
- 28:03And of course, one is much slower than the other.
- 28:05But I found that incredibly useful in the early days, particularly for debugging.
- 28:10And I still use the non-concurrent one if there's some tricky area that I want to focus
- 28:15on without having to worry about concurrency.
- 28:17So I found it's paid off in terms of saving my time as a programmer.
- 28:22And that's the other kind of time, isn't it?
- 28:24It's not just the processing or runtime of your software.
- 28:28It's the time you spend not just creating this stuff, but maintaining it.
- 28:34And concurrency can cost you a lot of maintenance.
- 28:39Oh, yes.
- 28:40Unless you're very careful.
- 28:41Yeah, I'm a strong advocate.
- 28:43Get the non-concurrent version working first.
- 28:45And of course, it may turn out that that's actually fast enough anyway.
- 28:50Absolutely.
- 28:51And then you've saved yourself a whole lot of trouble.
- 28:54It's sort of the whole premature optimization issues.
- 28:57Yeah.
- 28:57Yeah.
- 28:57It's easy to get seduced into doing things concurrently because it's very fashionable and you can brag
- 29:03about it.
- 29:04But quite honestly, it's got to be the right solution.
- 29:07And you're not going to know that until you've done a non-concurrent one first, I think.
- 29:11Yeah, that's a good point.
- 29:12And sort of related to that is the performance story.
- 29:16So you have some examples in your book where you write the concurrent version and then you have
- 29:22the concurrent version, but you write it in several ways.
- 29:24And you also have the serial version.
- 29:27That's right.
- 29:28Just to compare to see, to show what difference different strategies make depending on circumstances.
- 29:34Right.
- 29:35And for the CPU based one, you were doing like image analysis and processing.
- 29:39Yeah, because that's expensive in terms of CPU.
- 29:41And of course, if you use threading, it kills performance.
- 29:44Yeah.
- 29:45Ironically, in CPython, it's actually several times slower if you do it in parallel.
- 29:52Yeah, because it's only actually running on a single call at a time and you've got context
- 29:58switching on top of it.
- 29:59Whereas if you use multi-processing, Zoom, it can run free.
- 30:03You know, it'll max out your calls and it will go as fast as your machine's capable of.
- 30:07The performance story around threading is super hard to see the whole picture because we obviously
- 30:13know when you take a lock here, that slows down both the threads and the context switching
- 30:18is slow.
- 30:19But then you also have the sort of memory usage.
- 30:22You have the L1, L2 caches and registers.
- 30:25And so like when you switch from one thread to the other, it could pull in data that trashes
- 30:31your cache and you've got to go get it from main memory, which is like 100 times slower.
- 30:34And it's just, it's very subtle.
- 30:37And yeah, if you're networking, then generally using threads is fine because the network latency
- 30:44is so dominant.
- 30:46I'm not talking about in terms of if you're like Google and doing like massive servers,
- 30:51but for a lot of, if you like more ordinary applications, then threading is fine for that.
- 30:58But of course there is the new asyncio library.
- 31:01The GIL is basically one of the problems.
- 31:03It means you don't get any of the concurrency that you're aiming for computationally, but
- 31:07you still get all the overhead.
- 31:08Well, you don't get it at the Python level.
- 31:11You will get it at the C level.
- 31:12So if you have something that's running with Python threads and actually the work is being
- 31:19done by say a C library, if that C library is written well, it'll release the GIL, do its
- 31:26work and then reacquire it when it needs to pass data back.
- 31:29So it's, it's, it's not a simple story, no matter how you look at it.
- 31:33Yeah.
- 31:34Okay.
- 31:34So you still have, you've got a performance test, but you've got to have that serial version
- 31:38to give you a benchmark so that you know whether you're getting better or worse.
- 31:43Right.
- 31:43Absolutely.
- 31:44And also just doing that serial one, it will give you insights into the problem you're solving
- 31:49anyway.
- 31:49And it's better to make mistakes with the serial one than with the concurrent one because you've
- 31:53got less to think about then.
- 31:55Yeah, that's for sure.
- 31:56If you really do have a problem and it is slower, the trick is to use sub processes.
- 32:01Yeah, use the multi-processing module, which prior to 3.2, I found not terribly reliable,
- 32:09but they did loads of improvements in 3.2 and certainly in 3.3 and 4.
- 32:15It's absolutely rock solid, both Windows and Linux, which are the ones, the platforms I use.
- 32:20And it's brilliant.
- 32:22It's absolutely an excellent library.
- 32:24Yeah.
- 32:25And I just want to point out to people, like when you hear say use sub processes, that doesn't
- 32:28mean just go kick off a bunch of processes and manage it yourself, right?
- 32:31There's sort of a concurrent library for managing them, right?
- 32:35Multi-processing library.
- 32:37Oh, the multi- yeah.
- 32:38I mean, there's nothing to stop you.
- 32:40I mean, there is the sub process module.
- 32:42You can do it all manually, but there's no reason to do that.
- 32:45I mean, you can create a process pool.
- 32:48In one of my applications, I do that.
- 32:50And there's an asynchronous function.
- 32:53You can basically just give it a Python function and some arguments and say, okay, go do this
- 32:58somewhere else on some other processor.
- 33:00And it'll just do that work.
- 33:02If that's like expensive work, that's great because it doesn't stop your main process at
- 33:09all.
- 33:09And when it's done the work, it lets you know.
- 33:12And you can pick up from there.
- 33:14Right.
- 33:15So there's the concurrent futures module, which can be, which is a very high level module,
- 33:21which makes it really easy to just execute either with threads or processes stuff.
- 33:27Or you can go use the multi-processing module itself with its pools and stuff.
- 33:32So you can find the level that suits what you need.
- 33:35Yeah.
- 33:36It feels to me like if you're doing Python 3.2 or above, you should really consider maybe
- 33:42the concurrent module first and the concurrent futures, because it's so easy to say, let's
- 33:47do this computationally.
- 33:48Let's do this.
- 33:49Yeah.
- 33:49Let's do this as sub processes.
- 33:51Let's switch it to have like a pool of sub processes.
- 33:54All of those things.
- 33:56Right.
- 33:56Yeah.
- 33:56The other thing about multi-processing is by default, it doesn't share memory, which is
- 34:01the opposite of threading.
- 34:02Which means you're not going to clobber yourself by writing to something that's shared.
- 34:08Of course, it means if you do want to share, you have to actually go to extra effort and
- 34:13say, OK, I'm setting up this thing to be shared.
- 34:30Continuous delivery isn't just a buzzword.
- 34:33It's a shift in productivity that will help your whole team become more efficient.
- 34:36With SnapCI's continuous delivery tool, you can test, debug, and deploy your code quickly
- 34:42and reliably.
- 34:42Get your product in the hands of your users faster and deploy from just about anywhere at
- 34:48any time.
- 34:48And did you know that ThoughtWorks literally wrote the book on continuous integration and
- 34:53continuous delivery?
- 34:54Connect Snap to your GitHub repo and they'll build and run your first pipeline automagically.
- 34:59Thanks SnapCI for sponsoring this episode by trying them for free at snap.ci slash talkpython.
- 35:13Yeah, there's some built-in data structures for sharing across process, right?
- 35:17There are.
- 35:17I mean, I only use them personally for flags.
- 35:20You know, I tend to gather my data separately if I've got results data and then join it all
- 35:27up together at the end.
- 35:28So I just use flags basically to say, like, this bit's at this stage or a flag to say, look,
- 35:33just stop now because the user's cancelled.
- 35:36Yeah.
- 35:37To give me a clean termination.
- 35:39But, you know, I mean, I cover all that sort of stuff in the book.
- 35:42But it's a really great module, multiprocessing.
- 35:46But concurrent futures gives you that high-level approach, which makes it as simple as it can
- 35:52be for this kind of stuff.
- 35:54I mean, I'd still advocate not using concurrency unless you need it, you know, because it does
- 36:01make your program more complicated and harder to reason with, you know, or reason about.
- 36:06Yeah.
- 36:06And, you know, it is easy to switch between concurrent futures using subprocesses or using
- 36:12threads.
- 36:13But that doesn't mean the code that you write can be just flipped from one to the other because
- 36:17of the serialization issues and all, you know, the locking shared data.
- 36:21So that's maybe a really subtle thing you could run into.
- 36:24Well, if you're doing threading, the memory is shared by default.
- 36:30So any thread can stomp on anything, which can be a problem.
- 36:35But on the other hand, if you're using multiprocessing, any data that you're passing around has to
- 36:41be picklable, for example, which doesn't apply as a limit in threading because you're just
- 36:47accessing the same data in the same memory space.
- 36:49So there are differences and there are tradeoffs.
- 36:51And the API for multiprocessing started as mimicking the threading API, but it's actually
- 36:59grown considerably since then.
- 37:01So it's worth digging in and learning.
- 37:04But I start with the concurrent futures because that is the easiest conceptually and impractical
- 37:10code.
- 37:10It requires the least code to get stuff done.
- 37:12Yeah, absolutely.
- 37:13So both the multiprocessing and the threading are pretty good for when you're doing basic
- 37:21IO bound work, right?
- 37:22Because the key thing to know about that is a thread when it waits on a network call in
- 37:27CPython will release the gill, right?
- 37:29Yeah.
- 37:30But of course, there is the asyncio module, which is designed for that kind of work.
- 37:37I'm not a user of that module because most of my processing is CPU bound.
- 37:43Right.
- 37:43But that is a third way, if you like.
- 37:45Yeah.
- 37:46So in Python 3.4, they added the asyncio and the concept of event loops.
- 37:51And I also have not used that a lot.
- 37:53But my understanding is that's a little like the Node.js style of programming.
- 37:57I don't know because I avoid JavaScript as much as I can.
- 38:02But basically waiting on the IO bits and releasing it to process other bits of code, other methods
- 38:09while you're waiting on IO, right?
- 38:11So it's going to let you know rather than you having to poll or be blocked.
- 38:15Right.
- 38:15Very callback driven.
- 38:16Yeah.
- 38:17Yeah.
- 38:17Which is a perfectly good approach.
- 38:19Yeah.
- 38:20And then Python 3.5 added the async and await keywords.
- 38:24Yeah.
- 38:25Which I haven't used.
- 38:26I'm still using 3.4.
- 38:28Partly because I had some compatibility issues with CX Freeze at the time.
- 38:34And partly because of the installer.
- 38:36For my commercial software, I released both 32 and 64 bit versions on Windows.
- 38:43And up to 3.4, it's really easy to install both of those side by side.
- 38:52There's no problem.
- 38:53But with a 3.5 installer, what I found was that some third party libraries couldn't find one
- 38:59or the other.
- 38:59So I'm a bit stuck with 3.5 on Windows at the moment.
- 39:03Well, and the installer for Python 3.5 got a major reworking by Steve Dower, who was actually
- 39:11just on the show.
- 39:12What number was that?
- 39:13That was 53.
- 39:15So just, you know, a few weeks ago.
- 39:17And the installer is much nicer than the old one.
- 39:20It is, but it doesn't do what I want.
- 39:23But it has, you know, right?
- 39:24If you need this other thing it's not doing, then obviously you can't use it, right?
- 39:28Yeah.
- 39:28I need to be able to install 32 and 64 bit Python side by side.
- 39:34And I can do that up to 3.4.
- 39:35I'm not saying it's not possible.
- 39:37I mean, I have done it with 3.5.
- 39:40But what I haven't managed to do is get my third party stuff.
- 39:43PyWin32 and APSW, which I'll mention at the end.
- 39:48I couldn't get them working properly with it when I had both.
- 39:51They work fine when I've just got one Python, but not when I had both.
- 39:55But hopefully that problem will go away.
- 39:57Because, I mean, sometime I'm going to, like, stop doing 32-bit versions of my apps.
- 40:01I really want to look into the async and await stuff more.
- 40:06Because that programming model is so beautiful.
- 40:10It's just I haven't been writing any code that requires that type of work.
- 40:16I like that model because it's very similar to the GUI event loop model.
- 40:19I mean, the GUI event loop basically sits there and says, I'll let you know if something happens.
- 40:24And you say, okay, well, if this thing happens, call this.
- 40:28Yeah.
- 40:28GUIs are inherently event-driven, right?
- 40:31Absolutely.
- 40:32They've got their message pump and everything.
- 40:34So you actually, one of the, maybe the last section in the concurrency bit of your book, you talk about special considerations for GUIs.
- 40:43Yeah.
- 40:43I mean, I did this using TKinter simply because that's in the box.
- 40:47You know, comes with Python out of the box.
- 40:49Although, personally, I use PySide and Q.
- 40:51But it would work.
- 40:53The method works with both.
- 40:55And I'm sure it would work with WX or with PyG objects, any GUI system.
- 41:00And what I discovered was, how do you make, well, the question that arose for me was, okay, I've got a GUI application.
- 41:08And it's got to do some CPU intensive work.
- 41:11But I don't want to freeze the CPU.
- 41:13Because what if the user wants to cancel the operation?
- 41:15Or what if they just want to quit the application?
- 41:17I don't want it frozen for like, you know, minutes on end when they can't do anything.
- 41:21One of the quickest ways you can make a user believe that your application is crappy is to have it just lock up.
- 41:27And on Windows, like, get that sort of white, opaque overlay saying not responding.
- 41:32Or on OS X, it says force quit.
- 41:35You're like, hmm, I'm a little suspicious now.
- 41:38Yeah, and sometimes those messages come too early because sometimes, you know.
- 41:41But anyway, so that was the problem that I had to address.
- 41:44And what I found was, if I use threading, I do have a work thread and a GUI thread, the GUI still freezes.
- 41:51So what I needed was some way of not having the GUI freeze.
- 41:56And the model that I came up with was I have two threads, one for the GUI, and what I call, rather sarcastically, the manager thread.
- 42:05And the thing about the manager thread is the GUI gives it work.
- 42:08Whenever there's work to be done that's like CPU intensive, it gives it to the manager.
- 42:11But like a good manager, the manager never does any work.
- 42:14And that means that the GUI thread always gets all the CPU of its core, so it's never blocked.
- 42:21And the manager's given all the work and never does any work.
- 42:24And that solved the problem because what the manager does, it uses multiprocessing to hand it off to other processes.
- 42:30And if you've got multiple cores, that's no problem.
- 42:34I did try it on single core machines, and it was still no problem.
- 42:37Right, because you still have the preemptive multithreading that gives you enough time slice that your user feels like your app's working.
- 42:42So basically, you've got two threads.
- 42:45The GUI thread gets all the CPU for its core.
- 42:48And whenever it has work, it gives it to the manager who immediately hands it on to a process in a process pool.
- 42:56And that process is separate and goes off and does it and lets you know.
- 43:00And, of course, is cancelable if the user wants that.
- 43:03Right. Okay. Very, very nice.
- 43:04Because it basically, it shares one int.
- 43:07And the int is either going to say, like, you're good to go or, like, they don't want you anymore.
- 43:12Stop work.
- 43:14That model I cover in the book.
- 43:16And as I say, it'll work with any, although I show it with TK Enter, it's not TK Enter specific.
- 43:21Yeah, absolutely.
- 43:22I think that's a pretty good summation of the concurrency story.
- 43:26The other part of performance that you talked about that I actually don't know very much about and I haven't talked a lot about on my show is using Cython to speed up your code.
- 43:37Can you tell everyone what Cython is and give a quick summary there?
- 43:40Okay.
- 43:41Cython is basically, it's a kind of compiler.
- 43:47So, if you have an application written in pure, ordinary Python and you run it through Cython, it will create a C version of your code.
- 43:58And my experience is that will basically run twice as fast, just without touching it, without doing anything, just because it's now C.
- 44:08But you can then go further.
- 44:10You can actually give it hints and say, well, you can give it type hints.
- 44:15So, basically, you can say, well, this is an int or this is a string.
- 44:18And if you give it hints, it can optimize it better.
- 44:22It's also got optimizations for NumPy.
- 44:25So, for people who are interested in that kind of processing.
- 44:28So, it can produce very fast code for that.
- 44:31Yeah, that's interesting.
- 44:32And it's, I think, worth pointing out that it's not the same concept as type hints in Python 3.5, which is just more of an IDE tool, right?
- 44:40That's right.
- 44:41Typing module 4.3.5 is, in a sense, it has no functionality at runtime.
- 44:49It is purely used for static code analysis to say, you know, whether you're being consistent with your types.
- 44:56In other words, you're saying, I'm claiming that this is a list of strings and it will statically analyze your code and say, well, okay, you've only used it as if it were a list of strings.
- 45:07So, that's good.
- 45:09But, of course, a compiler could use that type hinting information to produce more optimized code.
- 45:16And I expect that's where things will go.
- 45:18Yeah, absolutely.
- 45:19I'm hoping that Cython will actually adopt that syntax.
- 45:23And that, I mean, there are other compilers like Nuitka and so on may adopt that.
- 45:27Now that typing is a standard module, one hopes that the third-party compilers will adopt it.
- 45:34Yeah, at least there's an option, right?
- 45:35Yeah.
- 45:36And it would mean consistent code then.
- 45:37It would mean you could write your code using typing and know that whichever one of the compilers you chose would give you some kind of speed up.
- 45:45Yeah, yeah.
- 45:46Beautiful.
- 45:46All right, so we don't have a lot of time left in the show, but I wanted to give you a chance to just talk about some of the projects on your website.
- 45:53One of the ones that you were working on is something called Diff PDF.
- 45:56Another one was the Gravitate Game.
- 45:58I thought those were kind of interesting.
- 45:59Oh, yeah.
- 46:00The game was just a bit of fun.
- 46:02I did it in one of my books.
- 46:04I think it's actually in Python practice because I'd never put a game in a book.
- 46:07And I thought, well, why not?
- 46:08I wrote it in TK Inter, but I have got cute versions.
- 46:12And on the website, I've got a JavaScript version that I did using the canvas, you know, the HTML5 canvas.
- 46:19It's basically the same game or tile fall, but with the things gravitating to the middle rather than falling to the bottom and left.
- 46:26That's it.
- 46:27And yeah, you can do fun games with Python, no problem.
- 46:30And of course, there is a Pi game library as well for people who are more sort of heavily into games.
- 46:35Yeah.
- 46:35Diff PDF is paying my salary.
- 46:39Basically, it compares PDFs and you might think, well, that's easy.
- 46:44You just compare the pixels and it can do that.
- 46:47And lots of other tools can do that.
- 46:48But what turns out to be quite tricky is comparing the text as text because PDFs are really a graphical file format.
- 46:58So a PDF file doesn't actually know what a sentence is or even a word.
- 47:02So it can break up text in quite weird ways.
- 47:05And this PDF gives you a sort of rational comparison.
- 47:08Yeah, cool.
- 47:09So you can ask questions like, is the essential content changed, not just like something bolded or whatever, right?
- 47:15Yeah.
- 47:16And I thought it'd be used by publishers.
- 47:18I wanted to use it originally to compare.
- 47:20If you do a second printing of a book, not a second edition, a second printing, the publisher will let you make minor corrections as long as it doesn't change the pagination.
- 47:30And having to like check that I hadn't messed up by looking at 300 or 400 or 500 pages was pretty tiring.
- 47:40So that was an incentive for creating this tool.
- 47:44You're like, within the time it would take me to do this, I could write an app and solve this.
- 47:47Exactly.
- 47:47But it turns out it's used by finance companies, insurance companies and banks.
- 47:53Ah, the lawyer types, yeah.
- 47:54Well, yeah, but why?
- 47:56And I don't know because they won't tell me.
- 47:58But they use it.
- 47:59And as long as they buy, I don't care.
- 48:03I mean, that's great.
- 48:04That's cool.
- 48:04And is that written in Python?
- 48:05It is.
- 48:06It was originally written in C++, but now it's written in Python.
- 48:10It uses concurrency, the model of concurrency I described.
- 48:12And it's a Windows-specific product.
- 48:16It uses a third-party PDF library that I bought, a royalty-free library.
- 48:23And yeah, that's been paying the way.
- 48:26But I've come up with another program, one that I originally wanted to write more than 20 years ago.
- 48:32But I didn't have the skill then, and the tools weren't available anyway.
- 48:37And that's X-Index.
- 48:38And it's for book indexes.
- 48:39And there are a couple of – well, there are some existing products out there for book indexes.
- 48:46But this one uses Python, and it uses SQLite, which I adore as a database.
- 48:51I really like it.
- 48:53Yeah, I'm a fan of it too.
- 48:54Yeah.
- 48:54So I get all the reliability and also the convenience.
- 48:58I mean, SQLite has full-text search, which I think people from Google added to it.
- 49:03And that's just absolutely superb.
- 49:05Oh, yeah.
- 49:05That's excellent.
- 49:06So that application has only gone on sale the end of last month.
- 49:11Wow.
- 49:11Congratulations on that.
- 49:12That's excellent.
- 49:13Thank you.
- 49:13So I'm really pleased about that.
- 49:15And I'm waiting to see – like people can use it for 40 days free trial now.
- 49:19So I'll see in a couple of months if people actually buy it.
- 49:23Well, good luck on that.
- 49:25That's great.
- 49:25Yeah.
- 49:26So before we end the show, let me ask you a couple of questions that I always ask everyone.
- 49:30Yeah.
- 49:31So there's close to 80,000 PyPI packages out there.
- 49:35And everybody uses some that are super interesting that maybe don't get the rounds that everyone knows about.
- 49:42So what are ones that you really like?
- 49:44Well, obviously, I use the PySite.
- 49:46I use the Roman one as well because I use Roman numerals like in the indexing thing.
- 49:51Nice.
- 49:51Yeah, I know.
- 49:52But the – and obviously, I use CX3s.
- 49:57And I use PyWin32, which is very useful for Windows.
- 50:01And I use – and another Windows one I use is WMI, which is Windows –
- 50:06Windows management infrastructure, I think.
- 50:07Thank you very much because I'd forgotten.
- 50:09But the one that I want to sort of boost, if you like, is APSW, another Python SQLite wrapper.
- 50:18And as you know, the Python standard library has a SQLite 3 module, which is perfectly good.
- 50:23Nothing wrong with that.
- 50:24But APSW is absolutely excellent.
- 50:28It provides you as a Python programmer with all the access to SQLite that you would get if you were a C programmer, but with all the pleasure of programming in Python.
- 50:39Oh, wonderful.
- 50:40So you can create your own custom functions in Python that you can feed into it.
- 50:45So you can create your own collations.
- 50:47You can even create your own virtual tables.
- 50:50Everything that you can do in C, you can do in Python.
- 50:53And it's just a fantastic library.
- 50:56It doesn't follow precisely the DBAPI 2 standard.
- 51:03It does where it can, but it favors – if there's a choice and like SQLite offers more, it offers you the more.
- 51:09Because it's designed to give you everything that SQLite has to offer.
- 51:13I mean, if you're wanting to prototype on SQLite for transferring to another database, then use the built-in SQLite 3.
- 51:21But if you want to use SQLite in its own right, for example, as a file format or for some other purpose where you're only going to be using SQLite, then APSW is the best module I've ever seen for doing that.
- 51:33Yeah, that's wonderful.
- 51:35While we're on database packages, I'll also throw out records by Kenneth Wright, which he called SQL for humans, which is like the simplest possible sort of alternative to DBAPI that I can find.
- 51:45It's like the opposite end.
- 51:47It's like super simple, not like, you know, we're going to give you access to everything.
- 51:51Okay.
- 51:51I mean, I like writing raw SQL, so APSW suits me for that as well.
- 51:56I mean, I know there are things like SQLAlchemy and, you know, that give you a higher level, but I love APSW.
- 52:01Yeah, wonderful.
- 52:02Wonderful.
- 52:03Okay.
- 52:03Last question.
- 52:04When you write some Python code, what editor do you use?
- 52:07I use gvim.
- 52:08gvim.
- 52:08Okay.
- 52:09Okay.
- 52:09So graphical vim.
- 52:10Now, I'm not saying that I'd recommend that.
- 52:12I think that it could drive, you know, someone insane trying to learn it because it is a strange editor, but I've been using it for more than 20 years now.
- 52:21I just, I would find it hard to use another one for daily work.
- 52:25All right.
- 52:25Excellent.
- 52:25Well, thanks for the recommendation.
- 52:26Okay.
- 52:27And thank you very much for having me on your show.
- 52:31Yeah, Mark.
- 52:32It's been a great conversation.
- 52:33And I'm really happy to shine a light on this whole concurrency story and the GUI story as well in Python because they don't get as much coverage as I think they should.
- 52:42No.
- 52:42And Python is good at both of those things.
- 52:45You know, I don't believe people who say otherwise.
- 52:48Python needs, gives you a lot of concurrency options, so you've got more choice and you need to choose with more care.
- 52:54But if you choose well, then it will give you great performance.
- 52:57Yeah, absolutely.
- 52:58All right.
- 52:59Well, thanks for being on the show.
- 52:59It was great to talk to you.
- 53:00Thank you very much.
- 53:03This has been another episode of Talk Python To Me.
- 53:06Today's guest was Mark Summerfield, and this episode has been sponsored by Hired and SnapCI.
- 53:11Thank you both for supporting the show.
- 53:13Hired wants to help you find your next big thing.
- 53:15Visit Hired.com slash Talk Python To Me to get five or more offers with salary and equity presented right up front and a special listener signing bonus of $2,000.
- 53:24SnapCI is modern, continuous integration and delivery.
- 53:28Build, test, and deploy your code directly from GitHub, all in your browser with debugging,
- 53:32Docker and parallels included.
- 53:34Try them for free at snap.ci slash Talk Python.
- 53:37Are you or a colleague trying to learn Python?
- 53:40Have you tried books and videos that left you bored by just covering topics point by point?
- 53:44Well, check out my online course, Python Jumpstart by Building 10 Apps at talkpython.fm/course to experience a more engaging way to learn Python.
- 53:53You can find the links from today's show at talkpython.fm/episodes slash show slash 58.
- 53:59Be sure to subscribe to the show.
- 54:01Open your favorite podcatcher and search for Python.
- 54:03We should be right at the top.
- 54:04You can also find the iTunes feed at /itunes, Google Play feed at /play, and direct RSS feed at /rss on talkpython.fm.
- 54:14Our theme music is Developers, Developers, Developers by Corey Smith, who goes by Smix.
- 54:18You can hear the entire song at talkpython.fm/music.
- 54:22This is your host, Michael Kennedy.
- 54:24Thanks so much for listening.
- 54:25I really appreciate it.
- 54:26Smix, let's get out of here.
- 54:29Staying with my voice.
- 54:31There's no norm that I can feel within.
- 54:33Haven't been sleeping.
- 54:34I've been using lots of rest.
- 54:35I'll pass the mic back to who rocked it best.
- 54:38I'll pass the mic back to who rocked it best.