Capturing output with input

2007-10-28 Thread gopala
Hi, I am pretty new to python but i do have experience with c++. As a
part of learning exercise i wrote a python script to insert
beautifying comments(with name, problem...) to our lab program source
files (c language).

The script is working for most of the cases. The problem is i also
need to append the test output of the lab programs to the
corresponding source files(again the output should be added as a
beautified comment). The lab programs are interactive and very
different from each other. Currently in the script, i am prompting the
user(me!) to manually enter the output of the program which it to be
inserted. I want to eliminate this tedious step.

for eg i want "python commenter.py lab1.c" to initially prepend
comments with my name... and then spawn lab1.exe , capture its output
and append it with comments to lab1_com.c

My initial attempts of using spawn.. , exec.. pipe.. failed since they
can't capture the std input and std output continuously.
The lab1.exe will be something like

Enter 2 nos
2 3
The sum is 5

Now i should be able to capture all these.
Is this possible ? If so please do give me some hints on how to
achieve this.

Cheers,
Gopala Krishna

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


Re: Capturing output with input

2007-10-29 Thread gopala
On Oct 29, 9:03 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:

> On Linux, use the "script" command.
> On Windows, select the region to copy using the mouse and paste it onto a
> notepad file.
> I don't think Python would help here.

Thanks :-)
Now  i just do os.system(exeFile) and i can easily copy the output
from terminal using mouse selection.

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


Load averages and Python threads on different Linux cloud provider setup

2011-05-31 Thread Mohanaraj Gopala Krishnan
Hello,

Apologies if this post is off topic.

We have a Python application that polls directories using threads and
inotify watchers. We have always run this application in a cloud
server provided by Voxel (http://www.voxel.net). We are currently
testing a different cloud server provider StormOnDemand
(http://stormondemand.com) and when we ran our application, our load
averages were a lot higher then they were when they were running on
the Voxel cloud server despite the specs being about the same (Refer
below for more details on setup). We have also ensured then when
testing the server was not handling any other loads.

I have written a simple test application (test_threads.py - attached,
or refer to http://pastebin.com/xGQU7JD0) that simulates the issues we
are seeing by starting up  threads that loops, sleeping for a user
defined time on each loop. It takes 2 parameters, the amount of
threads to start and the interval period.

When I run, "python test_threads.py 50 0.1" for about 10 minutes

Load average results:

StormOnDemand:
$ uptime
 18:46:22 up  7:29,  6 users,  load average: 4.43, 4.16, 2.93

voxel.net
$ uptime
 18:48:14 up 9 days, 15:09,  9 users,  load average: 0.51, 0.47, 0.43

The load average on the StormOnDemand server is a lot higher.

Python version:
StormOnDemand - 2.6.5
Voxel - 2.6.5

Server spec:
StormOnDemand - 8 x Intel(R) Xeon(R) CPU E5506 @ 2.13GHz; 16GB RAM;
230GB HDD (Storm Bare Metal servers)
Voxel - 7 x Intel(R) Xeon(R) CPU L5640 @ 2.27GHz; 14GB RAM; 200GB HDD
(VoxCloud servers)

OS:
StormOnDemand - Ubuntu 10.04 - 2.6.36-rc8101910 #1 SMP Tue Oct 19
19:18:34 UTC 2010 x86_64 GNU/Linux
Voxel - Ubuntu 10.04 -  2.6.32-31-server #61-Ubuntu SMP Fri Apr 8
19:44:42 UTC 2011 x86_64 GNU/Linux

Virtualisation method:
StormOnDemand - Not 100% sure, but I think they use Xen
Voxel - Not sure, but the image that we are using looks to us like a
stock standard Ubuntu 10.04 server

Any suggestion on why the load would be a lot higher or how I could
debug this further is greatly appreciated.


-- 
Mohan
#Simple script to test load when running python threads
# usage:
# python test_threads.py  
# e.g. :
# python test_threads.py 50 0.1
#

import sys
from threading import Lock, Thread
import logging
import time

logging.basicConfig()

log = logging.getLogger("test")
log.setLevel(logging.DEBUG) 

class MonitorDir(Thread):
def __init__(self, id, interval):
super(MonitorDir, self).__init__()
  	self.interval = interval 
self.id = id 
self._terminated = False

def finish(self):
if not self._terminated:
log.info('Terminating... %i'%self.id)
self._terminated = True

def run(self):
print 'Start threadi %i'%self.id

try:
while not self._terminated:
log.info('in id - %i \n'%self.id)
time.sleep(self.interval)
except:
log.exception('Unexpected error while monitoring')
finally:
log.info('Done monitoring')


if __name__ == '__main__':
mThreads = []
for i in range(int(sys.argv[1])):
print "create thread %i"%i
	mThread = MonitorDir(i, float(sys.argv[2]))
	mThreads.append(mThread)
	mThread.start()

while any(x.isAlive() for x in mThreads):
try:
	time.sleep(1)
except KeyboardInterrupt:
	log.debug('Exiting...')
	break
else:
   sys.exit(1) 

for mThread in mThreads:
mThread.finish()

for mThread in mThreads:
mThread.join()

sys.exit(0)
-- 
http://mail.python.org/mailman/listinfo/python-list