os.fdopen giving Invalid Argument from pipes

2009-02-19 Thread Tim Wintle
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

--
http://mail.python.org/mailman/listinfo/python-list


Re: os.fdopen giving Invalid Argument from pipes

2009-02-19 Thread Jean-Paul Calderone

On Thu, 19 Feb 2009 16:37:49 +, Tim Wintle tim.win...@teamrubber.com 
wrote:

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()


You got server_send and logger_receive backwards (also, i before e *except* 
after c et cetera).  Flip 'em around and all is well.


   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


Jean-Paul
--
http://mail.python.org/mailman/listinfo/python-list


Re: os.fdopen giving Invalid Argument from pipes

2009-02-19 Thread Tim Wintle
On Thu, 2009-02-19 at 11:50 -0500, Jean-Paul Calderone wrote:
 You got server_send and logger_receive backwards 

Doh!

 (also, i before e *except* after c et cetera).  Flip 'em around and
 all is well.

Thanks - never was great at speling :-)

Tim

--
http://mail.python.org/mailman/listinfo/python-list


Re: os.fdopen giving Invalid Argument from pipes

2009-02-19 Thread Scott David Daniels

Tim Wintle wrote:

On Thu, 2009-02-19 at 11:50 -0500, Jean-Paul Calderone wrote: ...

(also, i before e *except* after c et cetera).  Flip 'em around and
all is well.


Thanks - never was great at speling :-)


I used to be great at spelling until I became a programmer.  Programming
rewards consistency in spelling over correctness.  Spelling recievers
the same way 1000 times is better than getting it correct 999 times and
wrong once. :-)

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list