<div class="gmail_quote">On Wed, Nov 11, 2009 at 11:58 AM, Carsten Haese <span dir="ltr"><<a href="mailto:carsten.haese@gmail.com">carsten.haese@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Victor Subervi wrote:<br>
> Here's<br>
> a bigger code snippet with the entire try clause:<br>
><br>
>           if 14 < x < 20: # This just shows that it's a pic, not some<br>
> other type of data<br>
>             y += 1<br>
>             w += 1<br>
<div class="im">>             try: # It does this, because I've printed 'getpic1.py' etc.<br>
>               getpic = "getpic" + str(w) + ".py"<br>
>               try:<br>
>                 os.remove(getpic)<br>
>               except:<br>
>                 pass<br>
</div>>               code = """#! /usr/bin/python<br>
> import cgitb; cgitb.enable()<br>
> import MySQLdb<br>
> import cgi<br>
> import sys,os<br>
> sys.path.append(os.getcwd())<br>
> from login import login<br>
> def pic():<br>
>   user, passwd, db, host = login()<br>
>   form = cgi.FieldStorage()<br>
>   db = MySQLdb.connect(host, user, passwd, db)<br>
>   cursor= db.cursor()<br>
>   sql = "select pic%s from products where ID=%s;"<br>
>   cursor.execute(sql)<br>
>   content = cursor.fetchone()[0]<br>
>   cursor.close()<br>
>   print content<br>
> print 'Content-type: image/jpeg'<br>
> print<br>
> pic()""" % (str(w), str(i))<br>
>               script = open(getpic, "w") # I've deleted everything below<br>
> this line to the except to test<br>
>               script.write(code)<br>
>               print '<td><input type="hidden" name="%s" />\n' % str(x)<br>
>               os.chmod(getpic, 0755)<br>
>               print '<img src="%s" width="100"><br /><br /></td>\n' %<br>
> (getpic)<br>
>               count2 += 1<br>
>             except:<br>
>               print '<td>nope</td>'<br>
>           else:<br>
>             print '<td>%s</td>\n' % (field)<br>
>           x += 1<br>
<br>
If I'm understanding correctly what you're doing here, you're generating<br>
an HTML page with image tags, and at the same time you're generating the<br>
scripts whose purpose it is to serve the corresponding images' data.<br>
This is a terrible approach for the following reason: If two different<br>
users request this page for two different product IDs at roughly the<br>
same time, the getpic scripts for the first user will be overwritten by<br>
the getpic scripts for the second user before the first user's browser<br>
had a chance to issue its requests for the results for his getpic scripts.<br>
<br>
Rather than auto-generating on-the-fly variants of the getpic scripts<br>
that only differ in the picture number and product ID, you should have<br>
just one static getpic script that takes parameters from the URL that<br>
tell it which image number and product ID to use.<br></blockquote><div><br>I will do that after I fix the problem <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
This will fix your problem indirectly because then your script won't<br>
have to write out any files at all.<br></blockquote><div><br>No files are being written at all! No, this doesn't fix the problem! Please advise.<br>TIA,<br>V<br></div></div><br>