Python, DDE and Callbacks

M

Marco Aschwanden

Hi

I am trying to request a few hundred items from a DDE-server. At first I
connect and retrieve an item that let's me know, what items are available
(1). In the second part (2) I loop throug all the available items and
retrieves them from the DDE-server.
It takes about 5 minutes to retrieve all items because they are handled in
sequentially order. Placing all the dde-requests into an Excel-sheet and
opening the sheet retrieves all this values within seconds. Here is a
call-back handler at work.

How can I achieve the same within Python? Do I have to spread a thread for
each request? Or is there a simpler way?

Thanks for any hints in advance,
Marco


Here is a stripped down version of my client:

import dde
import time

ddeClient = dde.CreateServer()
ddeClient.Create("dde2db")
# open conncetion DDE-Server
ddeConversation = dde.CreateConversation(ddeClient)
# ConnectTo(service, topic)
ddeConversation.ConnectTo("\\\\DDESERVER\NDDE$", "DATA$")
if(ddeConversation.Connected() == 0):
print "\n\nERROR: No connection possible."
ddeClient.Shutdown()
sys.exit() # end program

#
# Which items are available? (1)
#
strItem = "AVAIL_ITEMS"

# I can't set a DDE-Timeout so I have to
# create my own timeout I will loop for 60 secs
startTime = time.time() + 60
answer = 'xxx'
timeOutCounter = 0
while (answer == 'xxx' and startTime > time.time()):
timeOutCounter = timeOutCounter + 1;
print "%d. try to retrieve valid funds for the internet" % timeOutCounter
try:
answer = ddeConversation.Request(strItem)
except:
# if the timeout is reached abort here if not,
# it will get into the next while loop
if (startTime < time.time()):
printLog("\n\nERROR: Request failed.")
ddeClient.Shutdown()
sys.exit()

# should have a tab-separated list with about 400 items
itemsToCall = answer.split("\t")

#
# Now retrieve all the items (2)
#
data = {}
for item in itemsToCall:
print "OK : Retrieving [%s]" % (item)
try:
data[item] = ddeConversation.Request(item)
except:
data[item] = "-"
print "ERROR: %s not available." % item

# Close the dde session
print "Done... Disconnecting..."
ddeClient.Shutdown()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top