question on multithreading, pipes

Discussion in 'Python' started by Jean-Yves Nief, Dec 15, 2003.

  1. hello,

    I have written a script which is performing some tasks in
    multithreading mode: the main thread is opening a connection to a
    distant server and all the threads that I start will have to perform
    actions on the remote server using the connection initiated by the main
    thread. At first sight, the only way I could achieve that in a proper
    manner (ie without having to open a connection to the remote server in
    every single thread and close it at the end of the thread) would be to
    use a pipe that I would use in all the threads, for example:
    * main thread:
    fw, fr = os.popen2('/bin/ksh')
    fw.write('Sinit')
    etc...
    * other threads:
    fw.write('perform action')
    etc...

    but if I do that, I need to queue the events, which means I have to
    serialize the jobs perform by the threads, which is clearly not what I
    want as I am using threads :)
    so my question is: how could I get around this without giving up
    multithreading ?
    any help appreciated.
    thanks,
    JY
    Jean-Yves Nief, Dec 15, 2003
    #1
    1. Advertising

  2. Jean-Yves Nief

    Aahz Guest

    In article <>,
    Jean-Yves Nief <> wrote:
    >
    >but if I do that, I need to queue the events, which means I have to
    >serialize the jobs perform by the threads, which is clearly not what I
    >want as I am using threads :)
    >so my question is: how could I get around this without giving up
    >multithreading ?


    Use a separate thread just to communicate with the remote server. This
    still causes some serialization, but at least everything else is
    independent.
    --
    Aahz () <*> http://www.pythoncraft.com/

    Weinberg's Second Law: If builders built buildings the way programmers wrote
    programs, then the first woodpecker that came along would destroy civilization.
    Aahz, Dec 24, 2003
    #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. Rob

    multithreading question

    Rob, Sep 8, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    357
  2. Madhusudan Singh

    Question about pipes

    Madhusudan Singh, Feb 13, 2004, in forum: C Programming
    Replies:
    31
    Views:
    1,134
    Alan Balmer
    Feb 17, 2004
  3. Kevin Walzer

    Question about pipes/os.popen

    Kevin Walzer, Sep 15, 2006, in forum: Python
    Replies:
    4
    Views:
    1,441
    Donn Cave
    Sep 15, 2006
  4. Jean-Baptiste

    question about I/O and pipes

    Jean-Baptiste, Dec 18, 2003, in forum: Ruby
    Replies:
    4
    Views:
    103
    Alfio Astanti
    Dec 23, 2003
  5. math math
    Replies:
    29
    Views:
    836
Loading...

Share This Page