Advice: socket handling and threads

Discussion in 'Python' started by Dan Williams, Feb 4, 2004.

  1. Dan Williams

    Dan Williams Guest

    Hi people

    Part of the reason I have started using Python (experience: 3 days) is that
    I recognise the potential benefits in using it compared to writing C/C++
    code. In particular, there are a couple of modules in an application that I
    am writing that I have calculated will be up to ten times quicker to develop
    (although it is hard to say at this stage), which is obviously quite
    attractive.

    The "problem" I have is relating to the existing C++ code I have. I've
    started porting it to Python, so that the whole project will be in the same
    language. The main aspects of my app that I am wondering about are socket
    handling and multi-threading.

    As far as I understand, Python can do everything that C/C++ can do with
    sockets, plus there are the thread and threading modules which I believe are
    equivalent to the pthreads module I have been using so far. My question is
    this:

    Is it sensible to port these sections of code to Python? Do I stand to gain
    or lose by doing this... I doubt the performance difference will be
    noticeable, and the only areas of the project that I would maybe consider
    extending in C++ are to do with parsing (and to be honest I think it'll be
    fine left in Python).

    Finally there is the cherry on the cake in the form of cross-platform
    compatibility. My C++ code only works on *nix (or cygwin) but as far as I
    understand it, my threads and sockets should work fine on Windows and Mac
    too, if done in Python...? (This is a CLI app not GUI by the way.)

    Thoughts and general musings will be greatly appreciated (as will any
    warnings of pitfalls I may encounter!)

    Dan
    Dan Williams, Feb 4, 2004
    #1
    1. Advertising

  2. > Is it sensible to port these sections of code to Python? Do I stand to
    > gain or lose by doing this... I doubt the performance difference will be
    > noticeable, and the only areas of the project that I would maybe consider
    > extending in C++ are to do with parsing (and to be honest I think it'll be
    > fine left in Python).
    >
    > Finally there is the cherry on the cake in the form of cross-platform
    > compatibility. My C++ code only works on *nix (or cygwin) but as far as I
    > understand it, my threads and sockets should work fine on Windows and Mac
    > too, if done in Python...? (This is a CLI app not GUI by the way.)
    >
    > Thoughts and general musings will be greatly appreciated (as will any
    > warnings of pitfalls I may encounter!)


    You should look into python twisted, a framework for networking. It has
    plenty of features. You can easily write portable networking code that
    makes use of select for dispatching, so you don't need to be multithreaded.
    It also supports reactors that are multithreaded, but in my expirience
    thats not necessary, as multithreading often is an excuse for easier
    handling of blocking io - which you avoid by the underlying select-based
    infrastructure.

    I had a mult-threaded client-server-app that also involved the serial line -
    porting it to twisted was easy and straighforward, and now I'm rid of all
    threads - which leads to way lower system load while the performance is the
    same.

    Regards,

    Diez
    Diez B. Roggisch, Feb 4, 2004
    #2
    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. Laszlo Nagy
    Replies:
    1
    Views:
    4,766
    Mark Wooding
    Jan 27, 2009
  2. Jean-Paul Calderone
    Replies:
    0
    Views:
    948
    Jean-Paul Calderone
    Jan 27, 2009
  3. Laszlo Nagy
    Replies:
    0
    Views:
    531
    Laszlo Nagy
    Feb 1, 2009
  4. Steve Holden
    Replies:
    0
    Views:
    648
    Steve Holden
    Feb 1, 2009
  5. Steve Holden
    Replies:
    1
    Views:
    702
Loading...

Share This Page