On Wednesday, June 3, 2015 at 3:41:15 PM UTC-5, M2 wrote: > Hello > I am trying to create multiple thread through the below program but I am > getting an error > > #! /usr/bin/python > import os > import subprocess > import thread > import threading > from thread import start_new_thread > > def proc(f) : > com1="ssh -B " > com2=line.strip('\n') > com3= " uname -a" > co=str("ssh -B ")+ str(com2) + str(" uname -a") > subprocess.call(co,shell=True) > print "----------------------------" > return > > f = open('/tmp/python/1') > for line in f: > t=thread.start_new_thread(proc(f),()) > t.start() > f.close() > c = raw_input(" Type anything to quit") > > > Execution output: > Linux abc.myhomenetwork.com 2.6.18-348.25.1.el5 #1 SMP Thu Apr 10 06:32:45 > EDT 2014 x86_64 x86_64 x86_64 GNU/Linux > ---------------------------- > Traceback (most recent call last): > File "./readfile1.py", line 19, in <module> > t=thread.start_new_thread(proc(f),()) > TypeError: first arg must be callable
Awesome Cameron. It works the way I want it to work. Thanks a lot guys. Here is the new code: #! /usr/bin/python import os import subprocess import thread import threading from thread import start_new_thread def proc(col) : P=subprocess.Popen(col, shell=True) return f = open('/tmp/python/1') for line in f: com1="ssh -B " com2=line.strip('\n') #com3= " /var/scripts/health/health.sh" com3= " uname -a " co=str("ssh -B ")+ str(com2) + str(com3) P=proc(co) f.close() Thanks a ton guys this should get me started on the greater program I am trying to write. -- https://mail.python.org/mailman/listinfo/python-list