Let's say you have a network server built around a single-threaded event loop—gevent, Twisted, asyncore, something simple you built on top of select.select, whatever. It's important to handle every event quickly. If you take 30 seconds responding to a requests from one connection, you can't deal with anyone else's requests, or accept new connections, for that whole 30 seconds.

But what if the request actually takes 30 seconds' worth of work to handle?

This is exactly what threads are for. You package up a job that does the 30 seconds of work and responds to the request when it's done, and kick it out of the event loop to run in parallel, then you can move on to the next event without waiting for it to finish.

The same thing applies to GUI programs.

People want sorted collections in the stdlib, but no one has ever made a solid proposal to add them.

Some people want a SortedList that maintains sorted order as elements are added and removed (without requiring linear-time shuffling); some want a SortedDict that keeps its keys in sorted order (and doesn't require hashing); SortedSet is less critical, but an obvious extension.

Every so often, someone proposes adding sorted collections to the stdlib.
4

You're writing a GUI app using Tkinter or PySide or your favorite GUI library, and testing it in-place, everything works.

Then you build a .app bundle out of it, double-click it in Finder, and it can't read your environment variables. (In fact, the "open" command, AppleScript, LaunchAgents… anything but directly running the program in the shell has the same problem.)

You check to make sure you've added them in your ~/.bash_profile. You open a new shell in Terminal, and there they are.

There's a pair of intertwined threads in python-ideas about coming up with a way to break out of list comprehensions and generator expressions early.

Oscar Benjamin gives a good example:

isprime = all(n % p for p in takewhile(lambda p: p**2 < n, primes_seen))

That's ugly.
4
Blog Archive
About Me
About Me
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.