[Pythonmac-SIG] PythonCGISlave conflict with SMTPlib? (MacOS 9, Pers. Web Sharing)

Bob Heeter bob@heeter.org
Sun, 20 Aug 2000 16:10:32 -0700


At 7:22 PM +0100 2000/08/20, Just van Rossum wrote:
> >I've been running my CGI applets in the background, so that was no problem.
>
>It's good to know that it works!

:)

> >FWIW, in addition to putting this email notification bit into 
>PythonCGIslave's
> >exception-handling code,
>
>(It's wiser to put your notifier in your CGI code, or write a module that
>does it for you, since it's very application specific: I don't think this
>stuff belongs in PythonCGISlave.)

I had just come to that conclusion after remembering that I'd originally
wanted to put the email notification in my CGI code.  I had resorted
to trying to put it in PythonCGISlave when it didn't work in my CGI,
and then (after spending hours trying to figure out why it still
didn't work) I'd forgotten what I was originally doing... :)

> >I've also added some code so that, when
> >a PythonCGISlave-based CGI applet is launched in LONG_RUNNING mode,
> >it loads in some persistent data from a file, and then periodically
> >reloads the data according to a programmable update schedule.
> >The CGI can then use the data without having to reload it every time it
> >gets asked to handle an event, which speeds up the response (on my poor
> >sluggish server at least).  I've also written a utility function for
> >easily sending email attachments.
>
>Same comment: you could do the same in a module (and modules don't get
>reloaded at each request, so you can store semi-persistent data there).

Ahh...  but that requires letting my brain get blown away (again) by the
subtle powers of Python!  I had no idea I could store data in a module
attribute without having it get reloaded on me every time the module
was imported. :)  Habits from the bad old days of C, C++, etc. die hard... :)

That was an excellent suggestion.  Everything now works beautifully here.

For those who are still watching, here is what worked:

In the CGI code:

	import cgiData
[...]
	myData = cgiData.theData
	myData = cgiData.reload(myData)
		# reloads my persistent data if necessary


In the cgiData module:

	theData = myDataClass()  # default instance of my data object

	def timeToRefresh(theData): # [...]

	def reload(theData):
		if ( notloaded(theData) or timeToRefresh(theData) ):
			theData = [ do a bunch of stuff ]
	return theData


N.B.  I tried this (seemingly more intuitive) version, but without success:

	import data_module
[...]
	cgi_data = data_module.getdata(mydata)

and then in data_module:

	MYDATA = 0

	def getdata():
		if ( (not MYDATA) or time_to_update() ):  # need to load database
			MYDATA = get_cgi_data()
		else:
			return MYDATA

Whenever I tried to run this, I got a Name Error exception on MYDATA,
at the if statement in the getdata function.  I was under the impression
that the function would be aware of the global variable in the module,
but that doesn't seem to be the case.  In the first version (above) I just
passed in the data attribute of the module explicitly.  Now that I've
got the first version working I kind of like it, but it wasn't the sort
of solution that popped into mind immediately.


	- YAHPP

(Yet Another Happy Python Programmer!)

Bob Heeter
Livermore, California