Python, DDE and Callbacks

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marco Aschwanden

    Python, DDE and Callbacks

    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.CreateServe r()
    ddeClient.Creat e("dde2db")
    # open conncetion DDE-Server
    ddeConversation = dde.CreateConve rsation(ddeClie nt)
    # ConnectTo(servi ce, topic)
    ddeConversation .ConnectTo("\\\ \DDESERVER\NDDE $", "DATA$")
    if(ddeConversat ion.Connected() == 0):
    print "\n\nERROR: No connection possible."
    ddeClient.Shutd own()
    sys.exit() # end program

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

    # 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(strIte m)
    except:
    # if the timeout is reached abort here if not,
    # it will get into the next while loop
    if (startTime < time.time()):
    printLog("\n\nE RROR: Request failed.")
    ddeClient.Shutd own()
    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.Shutd own()


Working...