Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #92035

Re: Multiple thread program problem

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 <gherron@digipen.edu>
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 <gherron@digipen.edu>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.148.1433401635.13271.python-list@python.org> (permalink)
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

Show key headers only | View raw


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 <module>
>      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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Multiple thread program problem Mohan Mohta <mohan.mohta@gmail.com> - 2015-06-03 13:41 -0700
  Multiple thread program problem Sam Raker <sam.raker@gmail.com> - 2015-06-03 14:01 -0700
    Re: Multiple thread program problem Mohan Mohta <mohan.mohta@gmail.com> - 2015-06-03 15:23 -0700
      Re: Multiple thread program problem Mohan Mohta <mohan.mohta@gmail.com> - 2015-06-03 16:45 -0700
        Re: Multiple thread program problem sohcahtoa82@gmail.com - 2015-06-03 16:56 -0700
          Re: Multiple thread program problem M2 <mohan.mohta@gmail.com> - 2015-06-03 17:04 -0700
            Re: Multiple thread program problem Cameron Simpson <cs@zip.com.au> - 2015-06-04 10:37 +1000
              Re: Multiple thread program problem M2 <mohan.mohta@gmail.com> - 2015-06-03 19:59 -0700
                Re: Multiple thread program problem Cameron Simpson <cs@zip.com.au> - 2015-06-04 14:42 +1000
  Re: Multiple thread program problem MRAB <python@mrabarnett.plus.com> - 2015-06-03 21:59 +0100
  Re: Multiple thread program problem Gary Herron <gherron@digipen.edu> - 2015-06-03 15:02 -0700
  Re: Multiple thread program problem M2 <mohan.mohta@gmail.com> - 2015-06-04 10:20 -0700
    Re: Multiple thread program problem Cameron Simpson <cs@zip.com.au> - 2015-06-05 08:58 +1000

csiph-web