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


Groups > comp.lang.python > #92016

Re: Multiple thread program problem

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!bcyclone03.am1.xlned.com!bcyclone03.am1.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <cameron@cskk.homeip.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'executed': 0.07; 'skip:/ 10': 0.07; 'wednesday,': 0.07; 'executes': 0.09; 'global,': 0.09; 'logic': 0.09; 'tuple': 0.09; 'argument': 0.15; '"f"': 0.16; '>on': 0.16; 'comma': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'proc': 0.16; 'recipe': 0.16; 'simpson': 0.16; 'stripped': 0.16; 'subject:program': 0.16; 'thread.': 0.16; 'tuple,': 0.16; 'tweak': 0.16; 'wrote:': 0.16; 'pointer': 0.18; 'variables': 0.18; 'variable': 0.20; 'meant': 0.22; 'rid': 0.22; 'subject:problem': 0.22; 'try:': 0.22; 'pass': 0.22; 'code,': 0.23; 'code.': 0.23; 'bit': 0.23; '2015': 0.23; 'passing': 0.23; 'cheers,': 0.24; 'header:In-Reply-To:1': 0.24; 'all.': 0.24; 'header:User-Agent:1': 0.26; 'figure': 0.27; 'not.': 0.27; 'disk': 0.27; 'executing': 0.27; 'issues.': 0.29; 'character': 0.29; 'function': 0.30; 'code': 0.31; 'probably': 0.32; 'generally': 0.32; 'getting': 0.33; 'lock': 0.33; 'file': 0.34; 'drop': 0.35; 'to:addr:python-list': 0.35; 'but': 0.36; 'being': 0.36; 'thanks': 0.36; 'assigned': 0.36; 'loaded': 0.36; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; '(2)': 0.37; 'instead': 0.38; 'ones': 0.38; '(1)': 0.38; 'end': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'content- disposition:inline': 0.60; 'your': 0.60; 'helps': 0.61; 'entire': 0.61; 'real': 0.61; 'times': 0.61; 'is.': 0.63; 'email addr:gmail.com': 0.64; 'forward': 0.65; 'cameron': 0.66; 'received:61': 0.72; 'wave': 0.72; 'back?': 0.84; 'hand.': 0.84; 'high,': 0.84; 'utc-7,': 0.84; 'why?': 0.91
X-Authentication-Info Submitted using ID cskk@bigpond.com
X-Authority-Analysis v=2.0 cv=XNWyuHdE c=1 sm=1 a=N2w12gWX+/QZiuybAQsWDA==:17 a=yEdEr6MRgwAA:10 a=kj9zAlcOel0A:10 a=vrnE16BAAAAA:8 a=ZtCCktOnAAAA:8 a=XAFQembCKUMA:10 a=pGLkceISAAAA:8 a=ugM3WpLNAAAA:8 a=Zoq4WPzElfnJDUj1PbkA:9 a=CjuIK1q_8ugA:10 a=N2w12gWX+/QZiuybAQsWDA==:117
Date Thu, 4 Jun 2015 10:37:56 +1000
From Cameron Simpson <cs@zip.com.au>
To python-list@python.org
Subject Re: Multiple thread program problem
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii; format=flowed
Content-Disposition inline
In-Reply-To <122a6965-5fe9-42bf-ba6d-393288121905@googlegroups.com>
User-Agent Mutt/1.5.23 (2014-03-12)
References <122a6965-5fe9-42bf-ba6d-393288121905@googlegroups.com>
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.139.1433378292.13271.python-list@python.org> (permalink)
Lines 51
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1433378292 news.xs4all.nl 2967 [2001:888:2000:d::a6]:38729
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 5907
X-Received-Body-CRC 602086108
Xref csiph.com comp.lang.python:92016

Show key headers only | View raw


On 03Jun2015 17:04, M2 <mohan.mohta@gmail.com> wrote:
>On Wednesday, June 3, 2015 at 6:56:47 PM UTC-5, sohca...@gmail.com wrote:
>> On Wednesday, June 3, 2015 at 4:45:52 PM UTC-7, M2 wrote:
>> > On Wednesday, June 3, 2015 at 5:34:31 PM UTC-5, Waffle wrote:
>> > > You think "(f)" makes a tuple, but it does not.
>> > > the parentesis is not the tuple constructor, the comma is
>> > > try:
>> > > t=thread.start_new_thread(proc,(f,))
>> >
>> > Thanks for the pointer waffle.
>> > The program executes now but still not the way I want it.
>> > I think I will need to tweak it a bit as the code is executing with the same argument from the file /tmp/python/1 multiple times whereas it needs to be executed only ones but in parallel. Let me figure that out.
>> >
>> >
>> > Once again thanks for all the help provided on this thread.
>>
>> Check your usages of "line" and "f".  You have spots where you probably meant "line" instead of "f", and others where you have "f" where you probably meant "line".
>
>Here is my logic:
>f is where the entire file is getting loaded

In the main code, yes.

>which is also passed as argument in the function proc

But why? f is not using in proc. Only line is.

>line has a single line from the file which is then stripped off the new line character and assigned to com2 variable which helps in using it in the subprocess.call

That end is fine.

I would be passing only "line" to proc, not "f" at all.

Suggestion: move your main code into its own function. That will make all the 
variables in it "local". Your proc function is presently relying on "line" 
being global, which generally bad and a recipe for disaster in multithreaded 
code.

Moving the main code into its own function will (1) get rid of the global 
variables and (2) force you to consider exactly what you need to pass to 
"proc", and that will help reveal various logic issues.

Cheers,
Cameron Simpson <cs@zip.com.au>

>>>How do you blip the throttle and wave? Do you blip it real high, then wave
>>>before the revs drop back?
>>Blip = right hand; Wave = left hand.  Do both simultaneously.  QED.
>Doesnt this make the bike lurch forward thru the intersection?
Not if the disk lock is in place...
        - Dean Woodward <deanw@agora.rdrop.com>

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