On Nov 2, 2009, at 2:13 AM, Andrew Francis wrote:
In the programme comments, there is the following:
  ..
in the future, if pickle-sieve.py is executed with a file name:

$python pickle-sieve.py sieve.dat
</block>

However you somehow missed this while pointing out all these other 'problems'?

I don't know why you put "problems" in scare quotes like that. I pointed out style differences with standard Python, I pointed out some ways to write it more tersely but where I recognized that you could have pedagogical reasons for being more explicit, and I pointed out a place where you might want more portability for Windows and explicitly said that I didn't know if it was a real problem. They are comments, which is what you asked for.


As for your comments in the code - when comments and code disagree, code wins. Here is your main code. I included the relevant snippet in my previous post but here I post the larger context

if __name__ == "__main__":

   signal.signal(signal.SIGINT, signalHandler)

   if len(sys.argv) == 2:
      fd = open('sieve.dat', 'r')
      image = pickle.load(fd)
      print image
      for t in image.tasklets:
          """
          we have to make sure that we are not inserting tasklets that
          were blocked.
          """
          if not t.blocked:
             t.insert()
      stackless.schedule()
   else:
      image = Image()
      image.makeChannel()
      image.makeChannel()
      image.makeTasklet(counter, image.channels[1])
      image.makeTasklet(sieve, image.channels[0], image.channels[1])

   while(True):
      if (flag):
         fd = open('sieve.dat','w')
         pickle.dump(image, fd)
         fd.close()
print "pickled ", len(image.tasklets),"and ", len (image.channels)
         break
      else:
         print image.channels[0].receive()

You can see the hard-coded filename for both saving and restoring. It does not matter at all which command-line parameter you give it, it will read from the file "sieve.dat". Search in the source code and you will see that it does not mention "sys.argv" anywhere else other than that 'if' line. There is no additional command-line processing -- and I'm completely fine with that simplicity.

What that means is that I did not do a thorough code review, but that's not my obligation.

(BTW, if you change the save to be 'wb' then the load should be 'rb'.)

When I reported my problem, I used an optional argument to exercise that code branch, I added a "print image" statement to that code branch to ensure that it was reading from that file and unpickling the right object. Everything worked as expected except that it started from the beginning. As I mentioned, my first reply then noted that it was likely because my version of Stackless is 2 years old. I'm not going to rebuild and investigate this problem because it obviously works for you on a modern Stackless install and I didn't plan on spending the 20 minutes it would take to download, rebuild, etc.


In doing so I am not interested in writing complex command line options that would greatly increase the size of the code. Or showing every little feature of Python.

Congratulations. And this has what to do with my comments?


                                Andrew
                                [email protected]



_______________________________________________
Stackless mailing list
[email protected]
http://www.stackless.com/mailman/listinfo/stackless

Reply via email to