os.fdopen giving "Invalid Argument" from pipes

Tim Wintle tim.wintle at teamrubber.com
Thu Feb 19 11:37:49 EST 2009


Was wondering if someone could point out what the stupid thing I'm doing
wrong is:


{{{
import os, time
def run_multi_proc():
    server_send, logger_recieve = os.pipe()
    pid = os.fork()
    if pid == 0:
        # we are the logger
        #os.close(server_send)
        logger_recieve = os.fdopen(logger_recieve)
        time.sleep(20)
    else:
        # we are the server
        #os.close(logger_recieve)
        server_send = os.fdopen(server_send,"w")
        time.sleep(3)
        os.kill(pid,signal.SIGTERM)

if __name__ == "__main__":
    run_multi_proc()
}}}


> python test.py

Traceback (most recent call last):
  File "test.py", line 20, in <module>
    run_multi_proc()
  File "test.py", line 9, in run_multi_proc
    logger_recieve = os.fdopen(logger_recieve)
OSError: [Errno 22] Invalid argument
Traceback (most recent call last):
  File "test.py", line 20, in <module>
    run_multi_proc()
  File "test.py", line 15, in run_multi_proc
    server_send = os.fdopen(server_send,"w")
OSError: [Errno 22] Invalid argument


really confused about why this isn't working - running on Linux with
python 2.5.2

Tim W




More information about the Python-list mailing list