[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1
translation of the help text with added links to sections and external sites and
Python’s webbrowser module, discussed earlier in this book, to open a browser. The
text help display is now redundant, but it is retained because the HTML display
currently lacks its ability to open source file viewers.

Thread callback queue speedup
The global thread queue dispatches GUI update callbacks much faster now—up
to 100 times per second, instead of the prior 10. This is due both to checking more
frequently (20 timer events per second versus 10) and to dispatching more callbacks
per timer event (5 versus the prior 1). Depending on the interleaving of queue puts
and gets, this speeds up initial loads for larger mailboxes by as much as an order
of magnitude (factor of 10), at some potential minor cost in CPU utilization. On
my Windows 7 laptop, though, PyMailGUI still shows 0% CPU utilization in Task
Manager when idle.
I bumped up the queue’s speed to support an email account having 4,800 inbox
messages (actually, even more by the time I got around to taking screenshots for
this chapter). Without the speedup, initial header loads for this account took 8
minutes to work through the 4,800 progress callbacks (4800 ÷ 10 ÷ 60), even
though most reflected messages skipped immediately by the new mail fetch limits
(see the next item). With the speedup, the initial load takes just 48 seconds—
perhaps not ideal still, but this initial headers load is normally performed only once
per session, and this policy strikes a balance between CPU resources and respon-
siveness. This email account is an arguably pathological case, of course, but most
initial loads benefit from the faster speed.
See Chapter 10’s threadtools for most of this change’s code, as well as additional
background details. We could alternatively loop through all queued events on each
timer event, but this may block the GUI indefinitely if updates are queued quickly.


Mail fetch limits
Since 2.1, PyMailGUI loads only mail headers initially, not full mail text, and only
loads newly arrived headers thereafter. Depending on your Internet and server
speeds, though, this may still be impractical for very large inboxes (as mentioned,
one of mine currently has some 4,800 emails). To support such cases, a new mail
config setting can be used to limit the number of headers (or full mails if TOP is
unsupported) fetched on loads.
Given this setting N, PyMailGUI fetches at most N of the most recently arrived
mails. Older mails outside this set are not fetched from the server, but are displayed
as empty/dummy emails which are mostly inoperative (though they can generally
still be fetched on demand).
This feature is inherited from mailtools code in Chapter 13; see the mailconfig
module ahead for the user setting associated with it. Note that even with this fix,
because the threadtools queue system used here dispatches GUI events such as
progress updates only up to 100 times per second, a 4,800 mail inbox still takes


Major PyMailGUI Changes| 1015
Free download pdf