[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版
def producer(self, id): for i in range(5): time.sleep(0.1) self.dataQueue.put('[producer id=%d, count=%d]' % (id, i)) def consum ...
threading thread might preclude a desired shutdown if nondaemonic. See Chapter 5 for more on program exits and daemonic threads ...
The main difference to notice here, though, is that we call the object pulled off the queue, and the producer threads have been ...
pop atomic?; 4E: runs at most N actions per timer event: looping through all queued callbacks on each timer event may block GUI ...
class ThreadCounter: def init(self): self.count = 0 self.mutex = thread.allocate_lock() # or use Threading.semaphore def incr(se ...
spawn batch of worker threads on each mouse click: may overlap text = ScrolledText() text.pack() threadChecker(text) # start thr ...
Example 10-21. PP4E\Gui\Tools\threadtools-test-classes.py tests thread callback queue, but uses class bound methods for action a ...
for i in range(self.reps): # access to object state here time.sleep(1) if progress: progress(i) # progress callback: queued if i ...
Probably the real answer to converting a non-GUI program is to truly convert it— restructure it to initialize widgets on startup ...
class Demo(Frame): def init(self,parent=None): Frame.init(self,parent) self.pack() Label(self, text ="Basic demos").pack() Butto ...
Note that this is different from using nested (recursive) mainloop calls to implement modal dialogs, as we did in Chapter 8. In ...
mechanisms, and the widget after method (or similar) is used by the GUI program to detect incoming output to be displayed. The n ...
import sys from socket import * port = 50008 host = 'localhost' def redirectOut(port=port, host=host): """ connect caller's stan ...
Example 10-25. PP4E\Gui\Tools\socket-gui.py GUI server side: read and display non-GUI script's output import sys, os from socket ...
Notice how we’re displaying bytes strings in Figure 10-14—even though the non-GUI script prints text, the GUI script reads it wi ...
(the non-GUI) can connect. One way or another, the GUI has to start before the non-GUI connects to it or the non-GUI script will ...
Notice the -u Python command-line flag used here: it forces the spawned program’s standard streams to be unbuffered, so we get p ...
window = Tk() Button(window, text='GO!', command=launch).pack() window.mainloop() The -u unbuffered flag is crucial here again—w ...
program exits. Exits are not necessarily graceful either (you get multiple error messages in the terminal window). Because of su ...
We might also use tkinter’s createfilehandler to register a callback to be run when input shows up on the input pipe: def callba ...
«
30
31
32
33
34
35
36
37
38
39
»
Free download pdf