popen in thread on QNX

Laszlo Zsolt Nagy gandalf at geochemsource.com
Thu Sep 8 07:46:23 EDT 2005


>>os.popen already creates a new process. So what if you try to call 
>>os.popen from your main thread, then pass the file descriptors to your 
>>thread?
>>It is just an idea...
>>    
>>
>
>But I need to run command from thread, that's the main reason to create 
>new thread :)
>  
>
Ok, but can't your main thread be a server thread with a queue?
Workflow example:

- one of your worker threads wants to run a command
- it creates the argument list and puts it into a message queue
- woker thread starts to sleep
- main thread processes the message queue -> it will run popen, put back 
the file descriptors into the message and wake up the worker thread
- the worker thread starts to work with the files

Or, if you create the new thread just to interact with that new process, 
why don't you call popen before you start the thread?
Well, of course this would increase the time needed to start up a new 
worker.

  Les




More information about the Python-list mailing list