[Zope] dealing with scripts that take too long

Tino Wildenhain tino at wildenhain.de
Wed Jan 25 17:45:42 EST 2006


martin f krafft schrieb:
> Hi there,
...
> I was thinking we could send data back to the browser, but I cannot
> figure out a way to do this from a TTW Python script. How can I send
> data immediately, not only when I 'return printed' after all the
> processing is done. NPH or so, I believe this was called with plain
> CGIs.

Actually it does not have anything to do with NPH, but thats another
story.

You can just write via context.REQUEST.RESPONSE.write(somestring)

When you start doing this, you are switching to "streaming" mode
and anything you return from that script is discarded.

This is especially important to know when exceptions occur -
you wont see them unless you take precaution

try:
    nasty_things()

except Exception,x:
    response.write("Error: %r\n" % x) # or something
    raise x # dont forget to reraise!

Or you look into the error_log object.

> Also, I would be interested in how other people approach this
> problem. `zopectl run` may be an alternative, but we'd rather not
> require filesystem access.

zopectl run is actually fine for maintenance. Its also easier to
avoid running the same script 100x the same time - as it can happen
with HTTP requests. A simple cron job, some locking, report via
email ... and you are done.

HTH
Tino


More information about the Zope mailing list