Advice on long running processes

2007-10-11 Thread commander_coder
Hello,

I write a lot of CGI scripts, in Python of course.  Now I need to
convert some to long-running processes.  I'm having trouble finding
resources about the best practices to do that.

I've found a lot of email discussions that say something like, "You
need to educate yourself about the differences when you have long-
running processes" but I've not had a lot of luck with finding things
that explain the differences.  I've seen some talk about database
timeouts, for instance, but I'm not sure I understand the problems.
Can anyone here suggest some resources?  I'd be happy with web sites,
with buying a book, anything.

I ask here because I write in Python and so if those resources used
Python then that would be super.

Thanks,
Jim

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Advice on long running processes

2007-10-11 Thread commander_coder
Thank you to folks for the replies.

Jim

-- 
http://mail.python.org/mailman/listinfo/python-list


tools to install not in python tree?

2008-03-03 Thread commander_coder
Hello,

I have some materials for a project that I am working on that I keep
in a source code control system (svn now, but I'm experimenting with
mercurial).  I want to install these things from the repository, but
not into site-packages/ as Distutils wants to do.

For instance there are some administrative scripts I want to put in ~/
admin/  and some programs that I want in ~/public_html/ .   I also
want to run some post-install routines (for instance, reset the
database tables on my development machine).  So I'm looking for a tool
to take things from a repository and install them into place.
Something like:
  install_from_repository.py -version "1.2.7"
if there is a bug in 1.2.7 that I need to work on.

Some of the things that I am looking for are like what setup.py does
(for instance, changing the #! line on scripts or having a
convenient .cfg file).  But as I understand it setup only targets
installing below sys.prefix; is that right?

I can write routines for myself but other people must need to do these
things also and a tested solution is obviously better.  Is there such
a tool?

Thanks for any help,
Jim
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tools to install not in python tree?

2008-03-04 Thread commander_coder
Thank you for the helpful replies.  I shall check out the links.  (I
looked at some setup.py's but mxBase was not among them.)

Regards,
Jim
-- 
http://mail.python.org/mailman/listinfo/python-list


unit testing a routine that sends mail

2010-02-18 Thread commander_coder
Hello,

I have a routine that sends an email (this is how a Django view
notifies me that an event has happened).  I want to unit test that
routine.  So I gave each mail a unique subject line and I want to use
python's mailbox package to look for that subject.  But sometimes the
mail gets delivered and sometimes it does not (I use sendmail to send
it but I believe that it is always sent since I can see an entry in
the mail log).

I thought that the mail delivery system was occasionally hitting my
mailbox lock, and that I needed to first sleep for a while.  So I
wrote a test that sleeps, then grabs the mailbox and looks through it,
and if the mail is not there then it sleeps again, etc., for up to ten
tries.  It is below.

However, I find that if the mail is not delivered on the first try
then it is never delivered, no matter how long I wait.  So I think I
am doing mailbox wrong but I don't see how.

The real puzzler for me is that the test reliably fails every third
time.  For instance, if I try it six times then it succeeds the first,
second, fourth, and fifth times.  I have to say that I cannot
understand this at all but it certainly makes the unit test useless.

I'm using Python 2.6 on an Ubuntu system.  If anyone could give me a
pointer to why the mail is not delivered, I sure could use it.

Thanks,
Jim

...

class sendEmail_test(unittest.TestCase):
"""Test sendEmail()
"""
config = ConfigParser.ConfigParser()
config.read(CONFIG_FN)
mailbox_fn=config.get('testing','mailbox')

def look_in_mailbox(self,uniquifier='123456789'):
"""If the mailbox has a message whose subject line contains
the
given uniquifier then it returns that message and deletes it.
Otherwise, returns None.
"""
sleep_time=10.0  # wait for message to be delivered?
message_found=None
i=0
while i<10 and not(message_found):
time.sleep(sleep_time)
m=mailbox.mbox(self.mailbox_fn)
try:
m.lock()
except Exception, err:
print "trouble locking the mailbox: "+str(err)
try:
for key,message in m.items():
subject=message['Subject'] or ''
print "subject is ",subject
if subject.find(uniquifier)>-1:
print "+++found the message+++ i=",str(i)
message_found=message
m.remove(key)
break
m.flush()
except Exception, err:
print "trouble reading from the mailbox: "+str(err)
m.unlock()
try:
m.unlock()
except Exception, err:
print "trouble unlocking the mailbox: "+str(err)
try:
m.close()
except Exception, err:
print "trouble closing the mailbox: "+str(err)
del m
i+=1
return message_found

def test_mailbox(self):
random.seed()
uniquifier=str(int(random.getrandbits(20)))
print "uniquifier is ",uniquifier  # looks different every
time to me
rc=az_view.sendEmail(uniquifier=uniquifier)
if rc:
self.fail('rc is not None: '+str(rc))
found=self.look_in_mailbox(uniquifier)
if not(found):
self.fail('message not found')
print "done"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unit testing a routine that sends mail

2010-02-18 Thread commander_coder
On Feb 18, 9:55 am, Roy Smith  wrote:
> Just a wild guess here, but maybe there's some DNS server which
> round-robins three address records for some hostname you're using, one of
> which is bogus.
>
> I've seen that before, and this smells like the right symptoms.

Everything happens on my laptop, localhost, where I'm developing.

I'm sorry; I wasn't sure how much information was too much (or too
little) but I should have said that.

Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unit testing a routine that sends mail

2010-02-18 Thread commander_coder
On Feb 18, 10:27 am, Bruno Desthuilliers  wrote:

> you could just mock the send_mail
> function to test that your app does send the appropriate mail - which is
> what you really want to know.

That's essentially what I think I am doing.

I need to send a relatively complex email, multipart, with both a
plain text and html versions of a message, and some attachments.  I am
worried that the email would fail to get out for some reason (say,
attaching the html message fails), so I want to test it.  I started
out with a simple email, thinking to get unit tests working and then
as I add stuff to the email I'd run the tests to see if it broke
anything.

I could mock the send_mail function by having it print to the screen
"mail sent" or I could have a unit test that looked for the mail.  I
did the first, and it worked fine.  I thought to do the second,
starting with a unit test checking simply that the message got to the
mailbox.  But I am unable to check that, as described in the original
message.

Jim
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unit testing a routine that sends mail

2010-02-18 Thread commander_coder
Bruno,  I talked to someone who explained to me how what you said
gives a way around my difficulty.  Please ignore the other reply.
I'll do what you said.  Thank you; I appreciate your help.

Jim
-- 
http://mail.python.org/mailman/listinfo/python-list