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


Groups > comp.lang.python > #83734

Threading in Python, Please check the script

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <cloverobert@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'beginner': 0.05; 'subject:Python': 0.06; 'except:': 0.09; 'skip:/ 10': 0.09; 'subject:script': 0.09; 'try:': 0.09; 'def': 0.12; 'suggest': 0.14; 'thread': 0.14; '"in': 0.16; '&quot;in': 0.16; '(none,': 0.16; 'func': 0.16; 'proc': 0.16; 'seconds.': 0.16; '\xc2\xa0if': 0.16; 'all,': 0.19; '8bit%:5': 0.22; 'command': 0.22; 'import': 0.22; 'to:name:python-list@python.org': 0.22; 'print': 0.22; 'script': 0.25; 'define': 0.26; 'second': 0.26; 'function': 0.29; 'correct': 0.29; 'message-id:@mail.gmail.com': 0.30; 'continues': 0.31; 'follows': 0.31; 'run': 0.32; 'running': 0.33; 'skip:# 10': 0.33; 'skip:t 40': 0.33; 'subject:the': 0.34; 'received:google.com': 0.35; 'skip:s 60': 0.36; 'done': 0.36; 'wrong': 0.37; 'two': 0.37; '8bit%:4': 0.38; 'to:addr:python- list': 0.38; 'skip:& 20': 0.39; 'skip:. 10': 0.39; 'to:addr:python.org': 0.39; 'unable': 0.39; 'how': 0.40; 'skip:\xc2 10': 0.60; 'break': 0.61; 'skip:t 30': 0.61; 'till': 0.61; 'first': 0.61; '8bit%:100': 0.72; '\xc2\xa0\xc2\xa0': 0.74; 'subject:check': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=MPWO+P91sMh8Y/yvZa2lWyHkXtkKr+MjWP/i1d3gVuc=; b=mKl703K5AXUYsjD1eIyFmL+NnLjm2qTqVFFRgTAACIUoifjte+hTTmtbAOx/VYw9P7 U9/Rj2/fH62VoO9pGambym207S4xaNkX4KqSwlr6WCIweBoJiPb+6RvB516AHM1w5XW6 +z8/CbO+bBBCUskvoKoN8s34Jl4sPjQXtTt1EhNHhegtdZNn1qKZXkZXcaUjRFAs1cQ2 vKCnU0WVujD0Ab1ALvoPsqzcZjOIWD0/pT8l+VuNBcLQ8XZRFDw+51XG77+r2SlA3iBm vki7RVW6BMKpgl449DEHN4VjpWhyqiGUDX99BvUWpReD+yvFL6YvsKDaddICoRIbXpcR QhGg==
MIME-Version 1.0
X-Received by 10.60.62.241 with SMTP id b17mr1395041oes.17.1421216530838; Tue, 13 Jan 2015 22:22:10 -0800 (PST)
Date Wed, 14 Jan 2015 11:52:10 +0530
Subject Threading in Python, Please check the script
From Robert Clove <cloverobert@gmail.com>
To "python-list@python.org" <python-list@python.org>
Content-Type multipart/alternative; boundary=001a11c21ca8783a0b050c96c2e7
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.17702.1421216540.18130.python-list@python.org> (permalink)
Lines 117
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1421216540 news.xs4all.nl 2874 [2001:888:2000:d::a6]:60390
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:83734

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

Hi All,

I have made a script in which i have started two thread named thread 1 and
thread 2.
In thread 1 one function will run named func1 and in thread 2 function 2
will run named func 2.
Thread 1 will execute a command and wait for 60 seconds.
Thread 2 will run only till thread 1 is running .
Again after that the same process continues in while after a break of 80
Seconds.

I am a beginner in python.
Please suggest what all i have done wrong and how to correct it.


#!/usr/bin/python

import threading
import time
import subprocess
import datetime
import os
import thread

thread.start_new_thread( print_time, (None, None))
thread.start_new_thread( print_time1, (None, None))
command= "strace -o /root/Desktop/a.txt -c ./server"
final_dir = "/root/Desktop"
exitflag = 0
# Define a function for the thread
def print_time(*args):
    os.chdir(final_dir)
    print "IN first thread"
    proc = subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
    proc.wait(70)
    exitflag=1

def print_time1(*args):
    print "In second thread"
    global exitflag
    while exitflag:
        thread.exit()
        #proc =
subprocess.Popen(command1,shell=True,stdout=subprocess.PIPE,
sterr=subprocess.PIPE)



# Create two threads as follows
try:
    while (1):
        t1=threading.Thread(target=print_time)
        t1.start()
        t2=threading.Thread(target=print_time1)
        t2=start()
        time.sleep(80)
        z = t1.isAlive()
        z1 = t2.isAlive()
        if z:
            z.exit()
        if z1:
            z1.exit()
           threading.Thread(target=print_time1).start()
           threading.Thread(target=print_time1).start()
        print "In try"
except:
   print "Error: unable to start thread"

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


Thread

Threading in Python, Please check the script Robert Clove <cloverobert@gmail.com> - 2015-01-14 11:52 +0530
  Re: Threading in Python, Please check the script sohcahtoa82@gmail.com - 2015-01-14 10:55 -0800

csiph-web