Aighearach has asked for the wisdom of the Perl Monks concerning the following question:

Here is my problem:

user comes to site. Fills out form to generate dynamic graphic. clicks "render."
the program generating the graphics calls Gimp::lock()
user gets impatient, clicks "reload."
Gimp::unlock() never gets called. Site is down

What is the best way to handle this? Is there a way to do something like an END block for a sub, or do I need a signal handler?

Replies are listed 'Best First'.
Re: embedded BEGIN and END?
by jjhorner (Hermit) on May 31, 2000 at 16:26 UTC

    What happens visually when someone clicks render? Do you stay on the same page? Do you send them to a "Generating graphic, please wait" page?

    I wouldn't give the user the option to submit more than once. Or, you could call an END block or end() routine to clean up any mess a user may have left. Or, have a pid-type file check before submitting the rendering job.

    You may have to do some sort of cookie thing to make sure that users can't submit more than one operation at a time.

    Just my $0.02.

    J. J. Horner

    Linux, Perl, Apache, Stronghold, Unix

    jhorner@knoxlug.org http://www.knoxlug.org

      Yes, submit sends them to another page.

      Cookies are against my religion for non-login situations. But even ignoring the second send, that wouldn't really stop the server from hanging, because it is the disconnect that creates the problem, not the reconnect.

      END doesn't work from inside a callback. unlock() has to be called from in the sub that calls it.

      Paris Sinclair    |    4a75737420416e6f74686572
      pariss@efn.org    |    205065726c204861636b6572
      I wear my Geek Code on my finger.
      
        How about IP-based session tracking? I've never tried it with Perl, but in ColdFusion you can store session variables in a database using the IP address as the primary key. It causes some minor problems with proxy servers, but it shouldn't cause a problem except in extreme circumstances. And if your beliefs don't permit cookies, well, you're limited in options, I would think.

        - Ozymandias

Re: embedded BEGIN and END?
by antihec (Sexton) on May 31, 2000 at 19:05 UTC
    Could you put your "rendering machine" in a perl daemon that's always running (and maybe spawning childs), and have the cgi just trigger a rendering process with the new args?
    this might depend on how you implement stuff, but with a little help from 'man perlipc' it shouldn't really be hard.
    plus, of course it could save you some startup and CPU time, cause the modules are already loaded in the daemon.
    -- bash$ :(){ :|:&};:
      Yes! I could do that, but then I lose all the benefits of having the code run inside mod_perl. Also, I don't want to fork off children, because of the amount of RAM it would use; it would lower the number of simultanious users that can use the service.
      Paris Sinclair    |    4a75737420416e6f74686572
      pariss@efn.org    |    205065726c204861636b6572
      I wear my Geek Code on my finger.
      
RE: embedded BEGIN and END?
by Aighearach (Initiate) on May 31, 2000 at 16:06 UTC
    Maybe it is because it is 5am by now, but I can't figure out how to edit my question, so I will just add this as a comment:
    Part of my problem is that I need to unlock() before exiting the sub. the sub being executed is a Gimp callback. The non-callback interface seems broken with the newest version; other things were broken in the earlier version, so I had to update.
    Am I going to have to run this part as a seperate daemon? Would that help, or would it just transfer the problem to a differnt pid?
    Paris Sinclair    |    4a75737420416e6f74686572
    pariss@efn.org    |    205065726c204861636b6572
    I wear my Geek Code on my finger.