Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'args': 0.04; 'method.': 0.05; 'python3': 0.05; 'f.close()': 0.07; 'skip:/ 10': 0.07; 'arg': 0.09; 'higher-level': 0.09; 'thu': 0.09; 'tuple': 0.09; 'typeerror:': 0.09; 'x86_64': 0.09; 'thread': 0.10; 'def': 0.14; '(also': 0.16; '2014': 0.16; 'edt': 0.16; 'subject:program': 0.16; 'subprocess': 0.16; 't.start()': 0.16; 'threading': 0.16; 'uname': 0.16; 'wrote:': 0.16; 'skip:" 30': 0.20; 'trying': 0.22; 'subject:problem': 0.22; 'module': 0.23; 'import': 0.24; 'header :In-Reply-To:1': 0.24; '(most': 0.24; 'header:User-Agent:1': 0.26; 'linux': 0.26; 'error': 0.27; 'module.': 0.27; 'callable': 0.29; 'running.': 0.29; 'function': 0.30; 'print': 0.31; 'skip:s 30': 0.31; 'probably': 0.32; 'getting': 0.33; 'traceback': 0.33; 'file': 0.34; 'to:addr:python-list': 0.35; 'execution': 0.35; 'skip:o 20': 0.35; 'but': 0.36; 'should': 0.37; 'received:10': 0.37; 'subject:: ': 0.37; 'skip:- 20': 0.37; 'level': 0.37; 'instead': 0.38; 'rather': 0.38; 'pm,': 0.39; 'to:addr:python.org': 0.39; 'charset:windows-1252': 0.65; 'here': 0.66; 'dr.': 0.69; 'yourself,': 0.72; 'received:204': 0.75; 'received:10.10': 0.76; 'institute': 0.77; '(425)': 0.84; '895-4418': 0.84; 'digipen': 0.84; 'herron': 0.84; 'smp': 0.84 Date: Wed, 03 Jun 2015 15:02:42 -0700 From: Gary Herron User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Multiple thread program problem References: <5eba09c9-aadb-46d9-b644-8ba775d8b97a@googlegroups.com> In-Reply-To: <5eba09c9-aadb-46d9-b644-8ba775d8b97a@googlegroups.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Mailman-Approved-At: Thu, 04 Jun 2015 09:07:14 +0200 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 64 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1433401636 news.xs4all.nl 2825 [2001:888:2000:d::a6]:52820 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:92035 On 06/03/2015 01:41 PM, Mohan Mohta 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),()) You are calling the function f yourself, but what you want here is for the thread to call f once it's running. So do t=thread.start_new_thread(proc, (f,)) # Procedure to call and a tuple of args for it. > t.start() I don't think the thread has a start method. > 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 > t=thread.start_new_thread(proc(f),()) > TypeError: first arg must be callable You should probably also consider using the higher-level threading module rather than the lower level thread module. (Also consider using Python3 instead of Python2.) Gary Herron -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418