Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Problem with Nose testing until forking process

Reply
Thread Tools

Problem with Nose testing until forking process

 
 
Jan Koprowski
Guest
Posts: n/a
 
      01-26-2009
Hi !

I write application witch sometimes need fork to shell based process
(some kind of shell command). I snatch stdin, stdout, stderr and two
additional streams and fork process to run command and get results.

# -*- encoding: utf-8 -*-

import os
import sys
import subprocess

def pipes_function():

global login_r, login_w, password_r, password_w

try: os.fdopen(3).close()
except OSError: pass
try: os.fdopen(4).close()
except OSError: pass

os.close(login_w)
os.close(password_w)
os.dup2(login_r, 3)
os.dup2(password_r, 4)

class BrokerProcess:

__slots__ = ['username', 'password', 'command', 'stdout',
'stderr', 'returned']

def run(self):

global login_r, login_w, password_r, password_w

login_r, login_w = os.pipe()
password_r, password_w = os.pipe()

wrapper = subprocess.Popen(args=('/usr/bin/special/wrapper'),
preexec_fn=pipes_function, bufsize=0, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)

os.close(login_r)
os.close(password_r)

login_w = os.fdopen(login_w, 'w')
password_w = os.fdopen(password_w, 'w')

login_w.write(self.username)
login_w.close()

password_w.write(self.password)
password_w.close()

self.command = self.command.encode()
wrapper.stdin.write(self.command)
wrapper.stdin.close()
self.stdout = wrapper.stdout.read()
self.stderr = wrapper.stderr.read()

self.returned = wrapper.wait()
return self.returned


My problem is that when I run nose test for function witch use this
broker i get followin errors (I test Pylons app):

File "/home/users/matrix/johny/Pylons/zhradmin/zhradmin2/zhradmin2/
controllers/account.py",
line 51, in login
account.login()
File "/home/users/matrix/johny/Pylons/zhradmin2/zhradmin2/model/
account.py",
line 29, in login
File "/home/users/matrix/johny/Pylons/zhradmin2/zhradmin2/lib/
brokerprocess.py",
line 41, in run
File "/usr/local/lib/python2.5/subprocess.py", line 594, in __init__
errread, errwrite)
File "/usr/local/lib/python2.5/subprocess.py", line 1091, in
_execute_child
raise child_exception
OSError: [Errno 9] Bad file descriptor

Is anyone know why I get error ?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Copy-on-write when forking a python process Heiko Wundram Python 3 04-12-2011 09:13 PM
Copy-on-write when forking a python process John Connor Python 0 04-08-2011 04:14 PM
Process forking on Windows Andrew Robert Python 9 05-19-2006 08:26 PM
forking a process felixfix@gmail.com C Programming 3 09-18-2005 04:18 PM
Forking sub-process in CppUnit? Roy Smith C++ 0 07-04-2003 12:58 AM



Advertisments