Python, DDE and Callbacks

Discussion in 'Python' started by Marco Aschwanden, May 21, 2004.

  1. 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()
    Marco Aschwanden, May 21, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?Miguel_Hern=E1ndez_Martos?=

    DDE Hotlinks in Python

    =?ISO-8859-1?Q?Miguel_Hern=E1ndez_Martos?=, Aug 25, 2003, in forum: Python
    Replies:
    1
    Views:
    606
    Syver Enstad
    Aug 29, 2003
  2. =?iso-8859-1?q?jonathan=20hunt?=

    DDE Python-C++

    =?iso-8859-1?q?jonathan=20hunt?=, Sep 27, 2003, in forum: Python
    Replies:
    0
    Views:
    416
    =?iso-8859-1?q?jonathan=20hunt?=
    Sep 27, 2003
  3. Chaos Master

    DDE using the Windows version of Python

    Chaos Master, Apr 25, 2004, in forum: Python
    Replies:
    1
    Views:
    3,333
    Peter Hansen
    Apr 25, 2004
  4. Robert Upton

    Python and DDE

    Robert Upton, Apr 6, 2011, in forum: Python
    Replies:
    0
    Views:
    379
    Robert Upton
    Apr 6, 2011
  5. eryksun ()

    Re: Python and DDE

    eryksun (), Apr 7, 2011, in forum: Python
    Replies:
    0
    Views:
    803
    eryksun ()
    Apr 7, 2011
Loading...

Share This Page