interactive mode in python with ctypes???

Discussion in 'Python' started by digitnctu@gmail.com, Dec 26, 2007.

  1. Guest

    Dear all:

    I am coming with problem, to apply ctypes under interactive mode
    in python.

    libdll.dll is a third-party library. The below code segment will
    run well under the batch mode(ie. python test.py 11060)
    but when I type sequencially it doesn't work as usual. Can any
    give me a hand??

    # file test.py begin
    from ctypes import *
    lib = CDLL("libdll.dll")
    def evCb(ev, clData, caData):
    print "event: ", ev,"=>" , string_at(caData)

    def run(port):
    libinf = lib.libCreate(0)
    lib.libConnect(libinf,port,0,0)
    evfptr = CFUNCTYPE(None,c_char_p, c_void_p,c_void_p)
    lib.libCltAddEventCallback(libinf,"AllEvents",evfptr(evCb),0)
    result = c_char_p()
    libbuf = raw_input("lib>")
    while libbuf != "quit":
    lib.libCallCommand(libinf,libbuf,0,pointer(result))
    print "result: ",result.value
    if libbuf == "Exit":
    break
    libbuf = raw_input("lib>")
    lib.libDestroy(libinf)
    if __name__ == "__main__":
    import sys,string
    run(string.atoi(sys.argv[1]))
    # file test.py end

    I type in interactive mode of python as below:

    from ctypes import *
    lib = CDLL("libdll.dll")
    def evCb(ev,clData,caData):
    print "event: ", ev,"=>" , string_at(caData)
    libinf = lib.libCreate(0)
    lib.libConnect(libinf, 11060, 0,0)
    evfptr = CFUNCTYPE(None,c_char_p, c_void_p,c_void_p)
    lib.libCltAddEventCallback(libinf,"AllEvents",evfptr(evCb),0)
    result = c_char_p()
    lib.libCallCommand(libinf,"somecmd",0,pointer(result))
    lib.libDestroy(libinf)
     
    , Dec 26, 2007
    #1
    1. Advertising

  2. En Wed, 26 Dec 2007 12:57:44 -0300, <> escribió:

    > libdll.dll is a third-party library. The below code segment will
    > run well under the batch mode(ie. python test.py 11060)
    > but when I type sequencially it doesn't work as usual. Can any
    > give me a hand??


    Define "doesn't work as usual"; at least describe what actually happens
    and what you expected to happen instead. If you get an exception, post the
    full traceback.

    > run(string.atoi(sys.argv[1]))


    string.atoi is deprecated eons ago; use int() instead

    --
    Gabriel Genellina
     
    Gabriel Genellina, Dec 27, 2007
    #2
    1. Advertising

  3. Guest

    On 12ÔÂ27ÈÕ, ÏÂÎç4•r40·Ö, "Gabriel Genellina" <>
    wrote:
    > En Wed, 26 Dec 2007 12:57:44 -0300, <> escribi¨®:
    >
    > > libdll.dll is a third-party library. The below code segment will
    > > run well under the batch mode(ie. python test.py 11060)
    > > but when I type sequencially it doesn't work as usual. Can any
    > > give me a hand??

    >
    > Define "doesn't work as usual"; at least describe what actually happens
    > and what you expected to happen instead. If you get an exception, post the
    > full traceback.
    >
    > > run(string.atoi(sys.argv[1]))

    >
    > string.atoi is deprecated eons ago; use int() instead
    >
    > --
    > Gabriel Genellina


    "doesn't work" means there is no result without exception. The python
    interpretter still run without complains; but when running under batch
    mode it run as the expectation. Are there difference for python
    interpretter between batch mode and interactive mode ?

    Thanks for Gabriel.
     
    , Dec 27, 2007
    #3
  4. ajaksu Guest

    You should get it to work with this loop (from run()):
    while libbuf != "quit":
    lib.libCallCommand(libinf,libbuf,0,pointer(result))
    print "result: ",result.value
    if libbuf == "Exit":
    break
    libbuf = raw_input("lib>")
     
    ajaksu, Dec 27, 2007
    #4
  5. Guest

    On 12ÔÂ27ÈÕ, ÏÂÎç10•r05·Ö, wrote:
    > On 12ÔÂ27ÈÕ, ÏÂÎç4•r40·Ö, "Gabriel Genellina" <>
    > wrote:
    >
    >
    >
    > > En Wed, 26 Dec 2007 12:57:44 -0300, <> escribi¨®:

    >
    > > > libdll.dll is a third-party library. The below code segment will
    > > > run well under the batch mode(ie. python test.py 11060)
    > > > but when I type sequencially it doesn't work as usual. Can any
    > > > give me a hand??

    >
    > > Define "doesn't work as usual"; at least describe what actually happens
    > > and what you expected to happen instead. If you get an exception, post the
    > > full traceback.

    >
    > > > run(string.atoi(sys.argv[1]))

    >
    > > string.atoi is deprecated eons ago; use int() instead

    >
    > > --
    > > Gabriel Genellina

    >
    > "doesn't work" means there is no result without exception. The python
    > interpretter still run without complains; but when running under batch
    > mode it run as the expectation. Are there difference for python
    > interpretter between batch mode andinteractivemode ?
    >
    > Thanks for Gabriel.

    sorry, I explain more precisely.
    "No result" means the callback function evCB will not be called as
    it in batch mode.
    For callback function, are there difference for python interpretter
    between batch and interactive mode ?
     
    , Dec 28, 2007
    #5
  6. On Thu, 27 Dec 2007 23:59:18 -0800 (PST), declaimed
    the following in comp.lang.python:


    > sorry, I explain more precisely.
    > "No result" means the callback function evCB will not be called as
    > it in batch mode.
    > For callback function, are there difference for python interpretter
    > between batch and interactive mode ?
    >
    >

    What interactive environment are you running under? Opening a plain
    command line shell and typing "python"? Running under IDLE's interactive
    window? PythonWin's interactive window?

    Note that you state this is a /callback/ function; as such it should
    be called when some underlying code detects the event for which the
    function is registered. Could it be that this underlying code does not
    get to run when using interactive mode (perhaps because the interpreter
    is blocked on a console read statement?) OR, more likely, looking at the
    original post -- YOU are not giving the system time to react to anything
    -- your "batch" version will block on a raw_input() call, which probably
    will free up whatever underlying code triggers the callback. Your
    "interactive" version creates AND DESTROYS the entire linkage at
    whatever speed you can type them... Try stuffing a few time.sleep(5)
    calls between each of the input statements... Or typing in what should
    have been the first try:

    import test
    test.run(11060)
    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
     
    Dennis Lee Bieber, Dec 28, 2007
    #6
    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. Alex
    Replies:
    1
    Views:
    338
    Peter Hansen
    Sep 9, 2005
  2. John J Lee
    Replies:
    3
    Views:
    552
    bruno at modulix
    Dec 1, 2005
  3. Edward Loper
    Replies:
    0
    Views:
    528
    Edward Loper
    Aug 7, 2007
  4. John J Lee
    Replies:
    0
    Views:
    561
    John J Lee
    Aug 7, 2007
  5. Edward Loper

    mmm-mode, python-mode and doctest-mode?

    Edward Loper, Aug 9, 2007, in forum: Python
    Replies:
    0
    Views:
    476
    Edward Loper
    Aug 9, 2007
Loading...

Share This Page