[Errno 9] Bad File Descriptor on Windows 2003 Server & Py 2.4.1

rbt rbt at athop1.ath.vt.edu
Tue May 3 13:13:45 EDT 2005


Dennis Lee Bieber wrote:
> On Tue, 03 May 2005 08:59:14 -0400, rbt <rbt at athop1.ath.vt.edu>
> declaimed the following in comp.lang.python:
> 
> 
>>The below script produces a '[Errno 9] Bad File Descriptor' when 
>>executed. If I remove the try: except: statements, the script stops when 
>>the error occurs.
>>
> 
> 	Might help to supply the traceback so one can examine the
> particular line in question...
> 
> 
>>             a = os.stat('C:\WINDOWS\System32\config\%s' %log)
> 
> 
> 	Might I suggest using os.path.join() rather than the % notation?
> 
> 
>>             if log == 'AppEvent.Evt':
>>                 print "old_size", app_size, "\n"
>>                 if cur_size >= app_size:
>>                     app_size = cur_size
>>                     time.sleep(6)
>>                     continue
>>                 else:
>>                     send_email(log, app_size, cur_size)
>>                     time.sleep(6)
>>                     continue
>>
> 
> 	Drop the laddered if: structure, and use a dictionary...
> 
> logs = {"AppEvent.Evt" : 0, "SecEvent.Evt" : 0, "SysEvent.Evt" : 0}
> 
> def send_mail(...):
>     ...
> 
> while True:
>     for log in logs.keys():
>         cur_size = os.stat(os.path.join("C:/windows/system32/config",
>                                                             log))[6]
>         if cur_size >= logs[log]:
> 	logs[log] = cur_size
>         else:
>              send_email(log, logs[log], cur_size)
> 
>         time.sleep(6)
> 
> 

This was my first go at it. I know it's not pretty, but it works ;) 
Perhaps when I refactor or offer it to friends, I'll incorporate your 
suggestions... as of now, I'm the only one who sees or uses it.

Thanks,
rbt



More information about the Python-list mailing list