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


Groups > comp.lang.python > #92035

Re: Multiple thread program problem

Date 2015-06-03 15:02 -0700
From Gary Herron <gherron@digipen.edu>
Subject Re: Multiple thread program problem
References <5eba09c9-aadb-46d9-b644-8ba775d8b97a@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.148.1433401635.13271.python-list@python.org> (permalink)

Show all headers | 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