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


Groups > comp.lang.python > #83747

Re: Threading in Python, Please check the script

Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.015
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'subject:Python': 0.06; 'assignment': 0.07; 'subject:script': 0.09; 'used.': 0.09; 'variables.': 0.09; 'works.': 0.09; 'cc:addr:python-list': 0.11; 'programs.': 0.14; 'assignment.': 0.16; 'bit.': 0.16; 'foot': 0.16; 'threads,': 0.16; 'files.': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'trying': 0.19; 'programming': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'script.': 0.24; "shouldn't": 0.24; 'specifies': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'right.': 0.26; 'least': 0.26; 'somewhere': 0.26; 'header:In-Reply-To:1': 0.27; 'external': 0.29; 'am,': 0.29; "doesn't": 0.30; 'absolute': 0.30; 'robert': 0.30; 'especially': 0.30; 'code': 0.31; 'trivial': 0.31; 'says': 0.33; 'running': 0.33; 'subject:the': 0.34; 'except': 0.35; 'but': 0.35; 'useful': 0.36; 'should': 0.36; 'changing': 0.37; 'wrong': 0.37; 'so,': 0.37; 'two': 0.37; 'little': 0.38; 'anything': 0.39; 'called': 0.40; 'break': 0.61; 'till': 0.61; 'new': 0.61; 'course': 0.61; 'simple': 0.61; "you're": 0.61; 'name': 0.63; 'provide': 0.64; 'school': 0.64; 'received:74.208': 0.68; 'programs,': 0.74; 'bite': 0.84; 'seldom': 0.84; 'subject:check': 0.84; 'to:none': 0.92
Date Wed, 14 Jan 2015 07:37:59 -0500
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0
MIME-Version 1.0
CC "python-list@python.org" <python-list@python.org>
Subject Re: Threading in Python, Please check the script
References <CAEMktPUaiQrEEhvK4okxfBzAynqZDM8c=a93dAo3cfJX1VcWRw@mail.gmail.com> <54B6479B.6080607@davea.name> <CAEMktPURDmUDsCX_4mUVkRUD8dagKEijsiGj87YGm5BGgFVaCw@mail.gmail.com>
In-Reply-To <CAEMktPURDmUDsCX_4mUVkRUD8dagKEijsiGj87YGm5BGgFVaCw@mail.gmail.com>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:OJpLLRn8uDv0Lszf1y+1m8rulVAk0kVZklboztEd8Nu lhck6CC/w8JW+LWPH0GbyNDouTLd4qolqkSDjhmRy4WwJd7/WK AlssaGkjDGHaj0Uo/bLcWBBSQVNsAfrhE0xF7kaTVynyNHXF6n 0kRPxFDUJi4XE4MFTRLJTbhFhE4kwXQQQYzXkRTQpQPbLfUv0d ieN7aZGXrxD5IdDdoiVjlzPvVr66s1l5VFWZfPUPsSRkMRrWqT bAT0NGX6IVTtgIl7VS4qV6XK9ePAamVUjHgZJwfiD26d54iAco MyG2cDVh8yR+fdNGsII4m5Izpo/B27xLv9Oa5NfFudJkLuMxKJ BsfbfEoou8pM+2IN3U5w=
X-UI-Out-Filterresults notjunk:1;
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.17715.1421239088.18130.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1421239088 news.xs4all.nl 2965 [2001:888:2000:d::a6]:36449
X-Complaints-To abuse@xs4all.nl
Path csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Xref csiph.com comp.lang.python:83747

Show key headers only | View raw


On 01/14/2015 07:11 AM, Robert Clove wrote:
> Can u provide me the pseudo script.
>
>
You say you're a beginner.  If so, you shouldn't be trying to use 
threads, which are tricky.  I've been programming for 46 years, and I 
seldom have had to write multi-threading code.

But this looks like a school assignment.  And it looks like the code has 
little to do with the assignment.  So let's break down the assignment a bit.

Your assignment says the two threads will be called thread1 and thread2. 
  So why do you call them t1 and t2?

Your assignment says the two functions will be called func1 and func2. 
So why do you call them print_time and print_time1 ?

The assignment doesn't say anything and about running an external 
process.  Since that's also complex and error prone, perhaps you should 
keep it simple till everything else works.

Some general principles:

1) try not to do the same thing in several places.  You create threads 
in 3 places, and two of them are wrong or at least non-optimal.  Keep 
just the one where you do it right.

2) Use useful names for the various variables.  Except of course where 
the assignment specifies the name to be used.  Then use that name.

3) Learn one new concept at a time.  If you're concentrating on threads 
here, don't try to learn subprocess at the same time, unless that's what 
the assignment calls for.

4) Avoid chdir, especially in multithreaded programs.  Use an absolute 
path if you must when dealing with files.  Except for trivial programs, 
changing the working directory is likely to bite you in the foot 
somewhere else in the program.


-- 
DaveA

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


Thread

Re: Threading in Python, Please check the script Dave Angel <davea@davea.name> - 2015-01-14 07:37 -0500

csiph-web