events/callbacks - best practices
Erik Max Francis
max at alcyone.com
Tue Oct 14 02:52:37 EDT 2003
HankC wrote:
> In delphi this would be something like:
>
> while 1:
> data = conn.recv(blocksize)
> if not data:
> break
> if assigned(OnProgress) then
> callback(data)
> conn.close()
>
> In other words, the class can handle a number of events but passing a
> callback function is not mandatory. If you want to handle an event,
> it is assigned and dealt with.
It's not fully clear to me exactly what you're asking, but it sounds
like the general answer is that the "callback" that you pass in can be
as complex as you want. Call it `handler':
handler.startProcessing()
while True:
data = ... get more
if not data and handler.notFinished():
break
if handler.acceptsData():
handler.accept(data)
conn.cloes()
handler.doneProcessing()
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ It's a winter day / Five years too late
\__/ En Vogue
More information about the Python-list
mailing list