Python Event Driven Serial Season
Seven months have passed since the final events of the second season, Rick has seemingly been forgiven by the group after the events that transpired, and once again, earns their trust. He has also seemingly taken charge of the group.
- Asynchronous (event-driven) programming is supported in the standard Python library in the asyncore and asynchat modules, which are very oriented to networking tasks (indeed they internally use the select module, which, on Windows, only supports sockets - though on Unixy OSs it can also support any file descriptor).
- Event-driven programming depends upon an event loop that is always listening for the new incoming events. The working of event-driven programming is dependent upon events. Once an event loops, then events decide what to execute and in what order. Following flowchart will help you understand how this works − Python Module – Asyncio.
Tonight before dinner, I happened to put on the sublimely beautifulalbum Set Yourself on Fire (2004), by Stars. The opening notes havealways struck me as a little. A gravelly voice intones, 'Whenyou have nothing left to burn, you have to set yourself on fire.' Wow.That's pretty intense. What kind of full-frontal musical assault isthe answer to that?Well, in Stars' world, full-frontal musical assaults just aren't thedone thing.
Think strings, piano, soft horns. Watch the video tohear for yourself.Then, after dinner, I happened to put on Megadeth's relentless 1988album So Far, So Good.
And then it hit me. All of asudden, I realized why the string/piano/soft horn intro always feltwrong. It's because Megadeth did a similar shtick 15 years earlier,and they did it right.Folks, I don't care if you're writing about setting yourself on fireor setting the world on fire, but get it right:Don't get me wrong: I think Stars are a fine band, and Set Yourselfon Fire is a brilliant, beautiful, wonderful album. It's a perfectexample of mid-2000s art pop. If you like thinking person's pop music,if you like melody and lyrics and talented musicians making it alllook effortless, you should just gonow. This is far and away the best album by Stars.
You can't go wrong.On the other hand, if you're more into full-frontal musical assaults,it's awfully hard to beat So Far, So Good. I'm onlyfamilar with Megadeth's first couple of albums (I lost interest afterRust in Peace), but this is the best of the early stuff.
From startto finish, it does not let up. And it certainly doesn't drag: thewhole album clocks in at just under 35 minutes. They don't waste anote. If you've ever wished a talented metal band would channel theraw energy and attitude of punk: it's been done, right here, andMegadeth did it better than anyone I can think of. They cover the SexPistols, they put you right in the shoes of a suicidal loser ('oh, howI lived my life for you / now, as I die, my flesh still crawls as Ibreathe your name'), and they utterly excoriate the risiblecensorship of the PMRC (in case you've never heard of them, it was an).That said, So Far is undeniably topical, political, and of its time.Maybe I like it so much because I was 16 or 17 when I first bought it,and it just stuck its hook in me. Maybe the kids today would find itdated.
Set Yourself on Fire is timeless pop, and only the style andinstrumentation give away its time and place (Montreal, 2004). Thelyrics will be as relevant, and as poignant, in 20 years as they aretoday.I love that two albums can be so utterly different, and yet both sogreat. No errorsFirst, let's implement a query function that never fails, just toestablish a baseline. This serves two purposes: it lets us see howmuch faster it is to completely ignore errors, and it shows theoverhead of an if or try where we never take the error path.# v1: cannot faildef getsomething1:if random.random. Rare errorsA more realistic scenario is when your query occasionally fails. Hereare two versions of the same query function, both rigged to fail 0.1%of the time:# v2: rare failure (0.1% probability) by returning Nonedef getsomething2:if random.random.
Frequent errorsFinally, let's modify the query function so that errors are frequent:# v4: frequent failure (30% probability) by returning Nonedef getsomething4:if random.random. ConclusionIt's safe to say that if is definitely not faster than try.That's clearly a false assumption, which is what I was expecting tofind.In fact, if might be slower than try, although I suspect minortweaks to the code (keep the happy path adjacent in memory) might makea difference. It's worth trying.And raise does have a noticeable overhead, but only if errors arefrequent. Another interesting experiment to do with this code is findout how frequent errors have to be before the overhead of raise isnoticeable.That said, if 30% of some operation results in an error, you probablyhave bigger problems than the overhead of raising an exception. Youmight want to look into more reliable infrastructure. Author:Published on: Sep 18, 2015, 12:06:42 PM - Modified on: Sep 19, 2015, 4:40:36 PM-is a great piece of software formanaging e-books. Not only is it great, it's open source.
What's notto like?OK, there is one thing not to like about Calibre: packaging andinstallation. The project actually advises againstusing OS-provided packages on the grounds that they are 'oftenbuggy/outdated'. And instead of providing a normaldownload-and-install process, Calibre expects you to download anunknown Python script which you then run as root.Sorry, Calibre, but no. I'm not going to give you complete access tomy computer to do anything you want with it. Author:Published on: Aug 30, 2014, 3:38:12 PM-At work, I've been hacking on a distributed system based on ZeroMQ.It's a nice library that hides away a lot of the fuss and bother ofnetwork programming, but still exposes enough detail that you have alot control over what's going on. However, the main mechanism formultiplexing I/O events is zmqpoll, which only accepts0MQ sockets or regular file descriptors.
But if you're doing networkI/O while running some work in child processes, you might want toblock until some socket is ready or some child process hasterminated. The carter 3 rapidshare download speed. How to do this with zmqpoll is not immediatelyapparent.As it turns out, there are several nice ways to solve this problem, inboth C and Python. Parent and childFirst, here's the setup: a parent process with one child at a time,where the child can terminate at any time.
The classic: SIGCHLD with an interrupted system callThe classic Unix answer is SIGCHLD, the signal that is delivered to aparent process when one of its children terminates. You normally don'thave to worry about SIGCHLD, since it's one of the few Unix signalsthat are ignored by default. But you're free to install a signalhandler for it so you can do stuff as soon as a child terminates.The nifty thing about signals is that they interrupt system calls, andZeroMQ's poll boils down to system calls. If ZeroMQ were tryingto be clever (too clever by half), it might catch those errors andretry the poll system call. Good news: ZeroMQ does not try to beclever. It does the right thing and exposes the interrupted systemcall to application code. (Pro tip: don't try to be clever.
Justexpose system errors to your caller with as little manipulation aspossible. Your callers will thank you in the end. Thank you, ZeroMQ!)So here's how it looks.
First, the signal handler:childterminated = Falsedef handlesignal(sig, frame):global childterminatedchildterminated = TrueThere's very little you can do safely inside a signal handler,especially in Python. Assigning a constant to a global variable isabout the only guaranteed safe action. (The reason is that just aboutanything you do might allocate memory with malloc, and thesignal might arrive while another malloc call is alreadyrunning. You cannot assume that the memory allocation system isre-entrant. Thus, you must avoid anything that might callmalloc, which in Python is just about anything.) (The otherthing you don't want to do is anything that might block, like readingfrom a socket or even writing to a local disk file. “Local” disk filesalways turn out to be on failing disks or flaky NFS servers at justthe wrong time.)Next, just inside main, we install the signal handler:def main:signal.signal(signal.SIGCHLD, handlesignal).as before.As a first attempt, let's modify the main loop to check thatchildterminated flag when poll returns.
Signalfd in PythonUnfortunately, current versions of Python (2.7.5 and 3.3.2 as I writethis) do not expose signalfd in the standard library. Luckily,Jean-Paul Calderone has written a wrapper, which you'll find in PyPI. The documentation is abit lacking and the API not quite complete, but I got it to work.I installed it withpip install -user python-signalfd(You'll want to leave out the -user option if you're using avirtualenv.)As with the C version, most of the changes are in main. There'sno more signal handler and no more childterminated globalvariable.Here's the code:def main:# list of signals that we're interested in (just SIGCHLD)mask = signal.SIGCHLD# block SIGCHLD from being handled in the normal way# (otherwise, the signalfd does not work)signalfd.sigprocmask(signalfd.SIGBLOCK, mask)# create the file descriptor that will be readable when# SIGCHLD happens, i.e. Author:Published on: Dec 18, 2013, 9:30:06 AM - Modified on: Aug 30, 2014, 3:38:01 PM-The other day, I was chatting with a friend who mentioned that he wasplanning to use his upcoming paternity leave to catch up on hisDoctor Who viewing.
And that he had seen none of the classic(1963-89) show!This is not like catching up on Mad Men or Game of Thrones, folks.We're talking 26 years of episodic TV. Furthermore, unlike programsbeing made today with high production values, good acting, andexcellent writing, the quality of Doctor Who over the years has beenspotty. And, oh yeah, it's a children's show which for the first 10years or so had no idea there might be adults watching. Finally, manyepisodes from those first 10 years are just gone: the BBC needed tofree up shelf space or precious videotape or something, so wiped thetapes to reuse them. (No, they're not on YouTube.)So unless you're able to devote hundreds and hundreds of hours towatching cardboard robots clamber about granite quarries whilespaceships with visibly attached strings fly overhead, you need to beselective. And if you've never seen any of those old episodes, wherewill you start? Well, you could do worse than ask a friend who's beenwatching Doctor Who since he was a teenager, has seen most episodesthat are still available (many of them twice) and has pretty strongopinions on most of them.
That'd be me. OrganizationThe organziation of Doctor Who has always been a bit complex. Thebasic unit is an episode, typically 25 minutes, broadcast fordecades on Saturdays around teatime. (Hey, it's a British show, so weget to use British units of time.) In the eighties they messed aroundwith slightly longer episodes shown on different days, but one thingnever changed: every episode was part of a longer serial. Most serialswere four episodes long; some were six, a few were two, and one epicfrom the early days was twelve episodes long.Each season (aka 'series' in British TV-speak) consisted of around5–8 serials. A couple of seasons (16, 23) shoehorned all theirserials into a connected story arc.Finally, the key to the show's longevity and inventiveness: everycouple of years the main character 'dies' and regenerates using a newactor, so it's obvious to group seasons by Doctor: first, second,third, etc.(Incidentally, the episode/serial thing forced the writers to insertan arbitrary cliffhanger every 25 minutes or so; this rarely improvedthe narrative. It also means the first little bit of each episoderecaps the cliffhanger from the previous episode, which is kind ofannoying when you're watching episodes back-to-back, rather than aweek apart as originally broadcast.)Anyways, I'm grouping things by Doctor, and recommending serials (inboldface).
There's little point in watching disconnected episodes,and watching whole seasons is rarely necessary (or even desirable).(There are a few negative recommendations snuck in there. They're alsoin boldface, so you actually have to read the text.). First Doctor (William Hartnell) (1963–66)In 1963, nobody had any idea that there were such things as Time Lordsand TARDISes. The audience had to learn about them from scratch, inthe very first story: An Unearthly Child. Unavoidably cheesy, inthat the writing and acting were aimed squarely at children under10—which is pretty much the case up until the Third Doctor. Butessential viewing, if only for historical reasons.The other thing nobody knew about in 1963 was Daleks, which is why thevery second serial, The Daleks, is also important. In fact, I'dargue there are really only two Dalek stories you need to see, andthis is one of them.One feature of early Doctor Who, sadly abandoned many decades ago,is the 'historical' story—i.e.
One set in earth's past with no sfelements. The first of these was Marco Polo, but all that remainsof that is audio and still photos. (Apparently the costumes and setswere quite impressive: the BBC always did have a flair for historicaldrama.) As second prize, perhaps try The Aztecs, the onlyhistorical serial from the first season to survive in its entirety.Unfortunately I have nothing to say on the rest of the First Doctor;I've only seen a couple episodes that I remember, and they were prettylame. I should specifically point out The Gunfighters as probablythe worst of the early serials. Before this, you might have thoughtthat the BBC was not meant to make Westerns; if you watch the wholething, you will realize that instead the BBC was meant specifically todo anything, ANYTHING, other than make Westerns.I'd like to say The Tenth Planet is essential on the grounds that itintroduces the Cybermen (as long-running bad guys, second only to theDaleks) and that it features the first ever regeneration. But I'venever seen it, and the fourth episode (with the regeneration scene) islost. Second Doctor (Patrick Troughton) (1966–69)Sadly, I have even skimpier knowledge of Second Doctor stories than ofthe First Doctor era.
Looking at the episode list on Wikipedia, thatshouldn't be a surprise, as only a handful of Troughton serials havesurvived the ravages of time.I do vaguely recall ploughing through the final Second Doctor serial,The War Games. It goes on and on for an interminable 10 episodes.Not very interesting, except that it's the first time we learn muchabout the Doctor's backstory, and it explains why the Third Doctorspends so much time on Earth. Third Doctor (Jon Pertwee) (1970–74)A number of good things happened when Doctor Who entered theseventies. Most obviously, the BBC splashed out and switched fromblack-and-white to colour. There are no more lost episodes (seeWikipedia for the tedious details of how various episodes wererecovered). Finally, the writing and acting got a bit better. Notgreat, mind you, but watching Pertwee episodes feels more likeentertainment and less like fanboy duty.The Third Doctor's debut serial, Spearhead from Space, is worthwatching because it introduces UNIT, a military outfit that defendsthe earth from alien invasion.
(Why doesn't the real world have one ofthese?) We also meet UNIT's commander, Brigadier Lethbridge-Stewart, alongstanding and much-loved recurring character. This serial alsointroduces the Autons, baddies who were revived along with the showin 2005.More importantly, Season 7 features the first serial that is great inits own right, not just as important background material: Inferno.It's a genuine nail-biter, with a mad scientist drilling STRAIGHT INTOTHE EARTH's MANTLE OMG. No Balrogs were harmed in the filming of thisserial, but it's a rip snorter all the same.Another long-running character is introduced in Terror of theAutons, the first serial of Season 8. I speak, of course, of theMaster. I don't remember this story terribly well, but the Master hasbeen a foil to the Doctor for so long, in so many serials, and wasplayed so deliciously well by Roger Delgado, that it's worthrevisiting his debut.Finishing up Season 8 is The Daemons, which exemplifies a minortrend in Doctor Who: giving a vaguely rational/scientificexplanation for apparently supernatural phenomena. I've always likedthis kind of story: they tiptoe close to the extremesuspension-of-disbelief required to enjoy horror, but end up making itsf in the end.There's nothing memorable from Season 9, but the Season 10 finalefeatures giant green glowing maggots. How can you go wrong with aserial called The Green Death?Season 10 opens with The Time Warrior, a fun story that introducesa new monster (the Sontarans) and one of the show's best sidekicks(Sarah Jane Smith).
I've always had a soft spot for serials thatactually use the TARDIS to cut between different times and places, andthis is one of them. Fourth Doctor (Tom Baker) (1974–81)Having skipped the Third Doctor's swansong, I suppose I shouldrecommend the Fourth Doctor's debut, Robot. It's moderatelyentertaining, but hardly essential. But it's always fun to meet a newDoctor. This serial also introduces the dapper and genial HarrySullivan, a companion for most of the next two seasons.The one essential serial from Season 12 is also the second essentialDalek story: Genesis of the Daleks. This is Doctor Who at itsbest: trench warfare, genetic engineering, (ab)using time travel tomeddle with history, a mad scientist who's also an evil dictator, abrutal ethical dilemma for the Doctor, and snapshots of real peoplecaught up in horrific events. Come to think of it, all televised sfshould strive for this.Season 13 features another classic: Pyramids of Mars.
Like TheDaemons, this one offers a rational explanation for an apparentlysupernatural phenomenon, and the phenomenon in this case is amemorably venomous bad guy. Most take-over-the-universe stories aresilly, but you can almost believe this particular bad guy pulling itoff—and you would not want to live in the resulting universe. Thisserial also takes advantage of the TARDIS as part of the story, ratherthan simply a device for dumping the characters somewhere new at thestart.I have a soft spot for The Hand of Fear from Season 14.
Althoughit's a typical rubber monster story, it's pretty entertaining. Thelast five minutes are important though: every so often we get areminder that the Doctor is not like us, and this is one of them. Ifyou find the story boring, that's OK, but at least watch the last fiveminutes of episode 4.Those last five minutes lead directly into The Deadly Assassin,which is mandatory viewing. It's one of the rare stories set onGallifrey, the Time Lords' planet. It features political intriguerather than rubber monsters. And it continues to cast the Doctor in aninteresting new light.And from there it's straight into The Face of Evil (wow, I guessSeason 14 was on a roll). Again, this is just plain good sf in its ownright, entertaining and thought-provoking in equal measures.
Plus itintroduces a new companion, Leela, who 1) kicks ass, 2) rarely (ifever) screams, and 3) isn't half-bad looking.Season 15 opened with Horror of Fang Rock, which eschewed bothrubber monsters and take-over-the-universe plots, substitutingpsychodrama in a tight, confined historical setting. Oh yeah, there'san exploding spaceship too, but it's a minor element. And this serialdemonstrates why Leela kicks ass.The Invasion of Time closes Season 15. It's another Gallifreystory, so another building block in the Doctor's (back)story. I don'trecall it being particularly great viewing, though.Season 16 was Doctor Who's first attempt at a season-long story arc.The first serial, The Ribos Operation, introduces both the arc andthe mysterious White and Black Guardians—Manichean figures lockedin an eternal struggle for the fate of the universe, sort of DoctorWho's answer to the two sides of The Force. Oh yeah, it's also a fineepisode in its own right: no mad scientists, nobody conquering theuniverse, just schemers trying to make a buck while the Doctorinterferes.The rest of Season 16 was pretty lame. The second serial, The PiratePlanet, is mildly interesting since it was written by Douglas Adams.It's not actually all that good, however.From Season 17, City of Death is great viewing: it incorporatestime travel, explains a hitherto-unknown historical mystery, and hassome good acting to boot.
There may have been a rubber monsterthreatening to take over the universe, but such things are OK inoccasional doses.I also quite liked Nightmare of Eden: imagine an Agatha Christiemystery set on a spaceliner in the far future, then add a Time Lordand TARDIS, some sort of weird transdimensional spaceship collision,and hallucinogenic drugs. Oddly enough, it all hangs together. Unnecessary revision historyThe 2011 and 2012 sites had remnants of revision history - presumablya feature of Pinax? The static archive only needs to show the finalrevision of each page, so I nuked the revision history:cd 2011hg rm -I 're./rev0-9+/' -I './history/.' .hg commit -m'remove old revision history'The interface for editing pages is useless, since it just redirects toa Django login page, which of course won't work in the static archive.Get rid of it:hg rm -I './edit/.' .hg ci -m'remove edit pages (they just redirect to the login page)'.
Mystery login pagesAll three sites had a bunch of mystery pages with paths like2011/account/login/index0000.html. I'm guessing there were linksfrom old revisions to those pages, which is why httrack captured them.Now that the old revisions are gone, make sure nothing left in thestatic site references them:hg locate -0 xargs -0 grep 'index0-9a-f0-9a-f0-9a-f0-9a-f'That found nothing, so remove them:hg rm account/login/index????html account/login/index????-?html account/signup/index????htmlhg ci -m'remove mystery index????html pages (unreferenced)'. Absolute linksThere were a bunch of gratuitous absolute URLs in links.
I found them,or at least the ones that were likely to be HTML attribute values,with this:hg locate -0 xargs -0 egrep -color=always '='https?://us.pycon.org/2011/' less -rFor a quick sanity check, I looked at the HTML source for some of thepages with absolute links: even in the dynamic, Django-generated site,the absolute links were there. Weird stylesheet namesSeveral.css files had weird URLs like/2012/sitemedia/static/css/pycon.css?10. That's OK in a dynamicsite, but doesn't work so well with static filenames. (In fact,httrack mangled those URLs: references to them in HTML remainedunchanged, but the files themselves turned out like pycond3d9.css- apparently some sort of failed URL escaping going on there.)Regardless: it's broken, so I fixed it:hg locate -0 -I '.html' xargs -0 perl -pi -e 's (/201d/sitemedia/static/css/.css)?d+ $1 g'hg ci -m'fix stylesheet naming oddity'. Author:Published on: Jun 21, 2013, 11:14:49 AM-Many years ago, I was one of the volunteer admins forstarship.python.net and mail.python.org. I also ran my ownpersonal email server for several years before giving in and switchingto Gmail. In both capacities, I regularly tinkered with theconfiguration of Exim, the MTA (message transfer agent, aka emailserver) used on all of those machines.
Every time I did so, I was alittle bit nervous that my change might break the existingconfiguration. So I did a flurry of manual testing each time.Now I'm trying to wean myself off Gmail and go back to running my ownemail server.
I still like Exim, so figured I'd stick with what I knowbest. But there's still that little problem: how do I know my emailserver configuration is correct, and how do I keep it correct whilechanging it?Of course the answer is obvious to a programmer: automated tests! Itturns out that I'm not the only one who has faced this problem.
Unlikeme, David North actually did something about it and wrote. The idea is simple: itruns exim -bhc (fake SMTP conversation) in a subprocess and teststhat the fake SMTP server behaves as expected. Author:Published on: Apr 24, 2013, 2:51:53 PM-When I started using Python in September 1998, I pretty quicklynoticed there was a problem in the ecosystem: every library thatincluded an extension module had its own little Makefile that cribbedfrom Python's own Makefile, which was (and still is) installedalongside the standard library. Libraries that did not includeextensions generally had a README file that said, 'copy foo.py toa directory on sys.path' and left it at that. The audience was prettyclearly fellow Python developers who wanted to use the library andknew exactly what sys.path was. Worst, anyone wanting to buildextension modules on Windows was on their own. This was no secret;everyone in the community at the time knew it was a problem, buteverybody was too busy with their own stuff to tackle it.
(Or they hadthe sense to stay well away from it.)So, in a nutshell, I started the distutils project. Well, OK, really Ischeduled a session at the 1998 International Python Conference (theprecursor to PyCon) called 'Building Extensions Considered Painful',with the goal of figuring out what we would do about it. A number ofpeople much smarter and more experienced than me were there, but Ionly remember Greg Stein and Barry Warsaw. About those unit testsI gather that the lack of unit tests is a frequent complaint foranyone who tries hacking on the distutils.
I thought the reason forthis was perfectly obvious until I had to explain it to Nick Coghlanin person at PyCon 2013. It's quite simple: distutils predates unittesting. Or at least, unit testing in Python. I'm sure Kent Beck hadsomething working in Smalltalk by then, but I was quite unaware of it.Anyways, it's pretty clear by looking at history:. 18 Dec 1998:. 15 Oct 2000: before burnout;-(.
21 Mar 2001:However, that does not excuse the lack of automated functional tests.For that, I have no excuse. I vaguely recall either 1) I didn't knowhow to do it, or 2) I didn't want to write a dedicated testingframework just for distutils. If I was doing it today, I couldprobably figure something out. But I know now more about programmingin general, and about automated testing in particular, than I didthen. Author:Published on: Mar 28, 2013, 6:08:42 PM-I like to tell people that my first PyCon was so long ago, it wasn'teven PyCon.
Back then, the community's big gathering was called theInternational Python Conference, and my first one was Houston inNovember 1998. That's surprisingly relevant to a big theme of PyCon2013 - more on that later. Despite a good string of attendance atIPCs from 1998 to 2001, this year was only my second PyCon (afterAtlanta in 2011).
Nutshell version: holy cow what anintense/exhilarating/crazy/overdrive experience. VolunteeringFor some reason it never occurred to me to volunteer at a conferencebefore. Especially considering that PyCon is almost entirely run byvolunteers, I now have to wonder: what was I thinking? This year Inoticed some tweets and emails encouraging people to volunteer, so Idid it. Turns out that volunteering at PyCon is how you peek behindthe curtain and nudge closer to the inner circle without having to doall that much. It's a brilliant scam, but it seems to work becausethere are a lot of people willing to do a bit, and some people willingto do a lot.The fun part was helping at the registration desk. I literally got offthe plane, took a taxi to the conference centre (with a gaggle ofother Montrealers who happened to be on the same plane), registeredand got my badge, and went right behind the desk to register otherpeople.
Oh yeah, there was a 5-minute training session in theresomewhere, so I had a vague idea what I was doing.The work part was being a session runner. This involves being in theGreen Room well before a given talk starts, making sure the speaker isthere, finding them if not, making sure their slides are saved, makingsure they can hook their laptop up to the projector, getting them tothe right room at the right time, and then leaving their interestingtalk halfway through to start the process again for the next talk. Imanaged to be late for my first session because I just plain forgot,which was a minor panic. Then, because irony exists as an actualphysical force in the universe, I was late for my second sessionbecause I was enjoying a leisurely lunchtime chat with MathieuLeduc-Hamel and Yannick Gingras about how great it is to volunteer atPyCon.
Ah well, it all came together in the end. Good talksAs usual, there was way too much interesting stuff on hand to seeeverything I wanted to see. Really, something must be done about thatnext year. Or we'll just have to stick with recording everything soyou can catch what you missed later on at home.Here are the talks that I saw in person and recommend:. Brandon Rhodes -.
Augie Fackler, Nathaniel Manista -. Luke Sneeringer -. Larry Hastings -. Allen Short -. Taavi Burns -There are a bunch more on my list of talks to watch on my laptopwhen too tired for programming but not tired enough to completelycollapse:. Brett Cannon -.
Laurens Van Houtven -. David Malcolm -. Doug Hellmann -.
Daniel Lindsley -. Raymond Hettinger -. Lynn Root -. Glyph -. Chris McDonough. And I just got tired of copying and pasting, despite being onlyhalfway through the list.
You get the picture: there were way moreinteresting-sounding talks than any one person could attend in person.(And if you view a talk from home that turns out to be boring, you canwalk away without hurting anyone's feelings!). PackagingI mentioned that there was a secret hidden connection between my firstInternational Python Conference in 1998, and PyCon 2013: packaging.Well, really, I should say build and packaging tools, since theproblem back in 1998 was building, but the problem today is packaging.The whole story is a bit long, so I'll write it up in. TL;DR: the basic design of distutils cameout of the 1998 conference, and I wrote most of the code from late1998 to late 2000. Standard build tool for Python libraries: problemsolved!But we punted on a couple of key issues, specifically dependencies andpackaging. My opinion at the time (1999) was that packaging was asolved problem: it's called Debian, or Red Hat if you prefer. Bothhave excellent packaging systems that already worked fine, and I feltit was silly to reinvent that wheel for one particular programminglanguage. If you need library X in your production environment, thenyou build a package of it using distutils.
When Harry Gebelcontributed the bdistrpm command to build a simple RPM frominformation in your setup script, that was a key step. We just madesure it was possible to build only the.spec file, because ofcourse you would often need to tweak that manually. Then I waited forsomeone to contribute bdistdeb, but it didn't happen.It turns out, unfortunately, that people persist in using deficientoperating systems with no built-in packaging system. More importantly,programmers like to use the latest and greatest version of library X,which is incompatible with OS vendors wanting to stick with stableknown versions. And building OS packages is a pain, especially whenyou're in development and playing around with libraries.Unfortunately, I burned out and lost the energy to keep working ondistutils before any of this became apparent. So over the years,various people have tried to address these problems in variousincompatible ways. I've pretty much ignored things, because after allpackaging was a solved problem for me (use OS packages, or buildyour own).Anyways, it appears that 2013 is the year the Python community hasdecided that enough is enough, and we need One True PackagingSolution.
As a result, there were a couple of packaging-relatedsessions at PyCon this year. Probably the most important developmentis that Nick Coghlan has volunteered (was volunteered?) to be the czarof all things packaging. I wish him well. Heck, maybe I'll evencontribute! Hallway trackI chatted with a number of people, some long-time acquaintances andsome total strangers.
I mentioned to several of them that I had beenusing Go for a couple of months, and every single one of them wasquite curious about it. So I definitely need to write up this Pythonhacker's view of Go.
(Nutshell version: largely positive, but I missexceptions.)I was also fairly shameless about looking for a job, which I've beenin the midst of for the past week or two. One piece of advice: PyConis an excellent place for programmers to look for work; the job fairreminded me of a two-way feeding frenzy. Another piece of advice:don't fire off a bunch of job application emails right before going toa conference. You'll spend way too much time hunched over yoursmartphone trying to type professional-sounding but still short emailmessages explaining that you can't really talk right now, but nextweek would be great. Maybe I should have bought one of those spiffyultra-light laptops so that whipping a real computer out forprocessing email isn't so painful. Open spaces & sprintsI scheduled two open spaces: a Mercurial clinic and a place to debatethe wisdom of extendding vs.
Embedding.I was late for the Mercurial clinic because of another reallyinteresting open space; many thanks to Augie Fackler for showing up ontime and fielding most of the questions. We fielded some basicquestions like, 'do I really have to merge this often?'
, explainingwhy it works that way, what the alternatives are, and so forth. Theusual stuff for someone new to DVCS.Augie also explained changeset evolution to a couple of people.Evolution is a very cool feature Mercurial has been growing slowlyover the past couple of releases to allow safe mutable history. As ofMercurial 2.5, it's good enough that Mercurial's developers are eatingtheir own dogfood and using it to develop Mercurial. I've also beenusing it heavily on personal projects. Hopefully it will be solidenough by 2.6 that enthusiastic power users can start to use itinstead of MQ.After the Mercurial Clinic, Augie and I popped into the Python 3Porting Clinic organized by Barry Warsaw.
That's when the real funbegan. Augie has been plugging bravely away at porting Mercurial toPython 3, and all is not well. Barry opened as a result of Augie's firstshowstopper bug, and I've been working on a patch. No doubt moreshowstoppers will follow. I stayed for the first day of sprinting, andspent the day alternating between fixing that bug and whining topeople about the various unpleasant ways of fixing it. I got to meetseveral thoroughly decent people in the process: Richard Jones, NickCoghlan, Toshio Kuratomi, and Buck.
Umm, sorry Buck, I didn't catchyour last name.My other open space was intended to spark a little debate aboutextending vs. I've been working on that revolves around embedding 'real'languages like Python, and suffered a minor crisis of confidence whenI stumbled across Glyph Lefkowitz's from 2003.So I was hoping this session would clear the air a bit. Iguess I should have invited Glyph personally. My personal suspicion isthat there do exist valid use cases for embedding, but you had bettermake damn sure it's the right choice. 'When in doubt, chooseextending' is not as strong as Glyph's stance, but there you go. It'smy opinion today. Wrap upEverybody knows that the language is great, and that the library is(mostly) great too.
Likewise, the collection of modules on PyPI is agood thing (if a bit overwhelming).But honestly, it's the people that make hacking in/on/with Python sofun and rewarding. I know there is a stereotype of programmers asanti-social, maladjusted, unpleasant people, but that stereotype justvanishes at PyCon. Whether chatting with total strangers who I'llprobably never meet again, or reconnecting with former colleagues, ormeeting people who I've only 'known' online before, PyCon is justabout the friendliest and most welcoming environment I've ever beenin. That's just as true with 2,500 people in 2013 as it was with250 in 1998. Author:Published on: Mar 28, 2013, 6:08:42 PM-I'm working on written in Go, andI've gotten to the point where I need to pick a command-line parsinglibrary. I'm not fond of the standard package for a couple of reasons:.
its syntax does not follow GNU conventions. its default help output is uglySo I thought I'd shop around and see what's out there. What followsare my impressions of all the command-line parsing libraries listed inthe.Disclaimer: I'm the original author of the Python standard librarymodule optparse, so I'm biased in favour of convenient, automatedconversion of command-line options to programmer-accessible variables.I also like automatic generation of nice-looking help. And I preferGNU style:.
single dash for short options ( -v). multiple short options can be coalesced ( -ab is equivalent to -a -b). double dash for long options ( -verbose). options terminated by lone -. options can be interspersed with positional argsExecutive summary: I evaluated 8 of the libraries listed in the GoProject Dashboard.
Three of them look promising:. launchpad.net/gnuflag. github.com/gaal/go-options. github.com/ogier/pflagThe remainder appear to be incomplete and/or abandoned (eg. They don'tbuild, are undocumented, or have no unit tests).All evaluations were done with Go 1.0.3 using the latest version ofeach package as of December 18, 2012. Github.com/gaal/go-optionsYet another implementation of GNU/POSIX syntax, but using a totallydifferent API from flag.
You write a big string that describes allof your options, and the library parses it at runtime and then parsesthe command line. Panics if your specification is malformed.Pros:. mostly works as advertised: implements some of GNU/POSIX syntax. nicely documented.
Event Driven Program Python
tested. easy-to-use API. generates decent-looking help. compiles and works (modulo limitations below)Cons:.
does not support option clustering ( -ab equivalent to -a -b). similarly, does not treat -abfoo as equivalent to -a -b foo. sloppy syntax: treats -verbose equivalent to -verbose. some people might dislike the dynamic API and prefer compile-timechecking (doesn't bother me). Code.google.com/p/optparse-goAppears to be based on my Python module optparse, so I have aninherent bias in favour of this one.
Unfortunately, it doesn't build.Pros:. should implement all of GNU/POSIX syntax, since optparse does. should support option aliases, since optparse does. should support abbreviation of long options, since optparse does(the above are presumptions, not verified by reading the code or trying it)Cons:. not compatible with 'go build' (mixed packages in same directory).
uses lots of obsolete library packages (needs 'go fix'). even then, it still doesn't compile.
no documentation.
events = Events(( 'onthis ', 'onthat '))# this will raise an EventsException as `onchange` is unknown to events: events.onchange += somethingchanged DocumentationComplete documentation is available at InstallingEvents is on PyPI so all you need to do is: pip install eventsTestingJust run: python setup.py testOr use tox to test the package under all supported Pythons: 2.6, 2.7, 3.3, 3.4, 3.5 and 3.6. LicenseEvents is BSD licensed. See the for details. ContributingPlease see the. AttributionBased on the excellent recipe by, Copyright (c) 2005.