event loop problem

alex116321 at my-deja.com alex116321 at my-deja.com
Mon Oct 23 14:53:10 EDT 2000


I am trying to write a simple Python script which which uses ADO
through Python's COM extension but never exit.  For this I have writen
a simple while loop however this causes a problem on Windows NT.
Sometimes other windows on NT broadcast messages which need to be
confirmed by all running windows.  If at least one window does not
dispatch the confirmation, the broadcaster will hang.  In C++ the
solution is to make the main event loop listen for windows messages,
for example:

while(PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE)) {
  TranslateMessage(&msg);
  DispatchMessage(&msg);
}

However, I cannot seem to find an equivalence in Python except to use
Tkinter and use the mainloop function.  Unfortunately, I do not require
any graphics in my program.  This is my Python script:

######################################################
import time, win32com.client

# Dispatch Microsoft ActiveX Data Objects (ADO)
rset = win32com.client.Dispatch("ADODB.RecordSet")

query = "select cAFUserAccountP from Person"
dbstring = "DRIVER={SQL Server};SERVER=svr-tor-
dev;DATABASE=SMS_HP_1.2.0;UID=sa;PWD="

rset.Open(query, dbstring)
rset.Close()

while 1:
   time.sleep(0.01)

##########################################################

While this script is running, try setting the time through the windows
Date/Time Properties window.  The window will get stuck until the
python script is killed.  This is because it tries to broadcast a
message but the python application window does not respond.  Actually,
ADO opens a hidden window and causes this problem.  If ADO is not used,
no problem exists.  Any help would be greatly appreciated.



Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list