Hi Ayal and Dan,
    Attachment is the file reproducing the bug, it is verified on
python2.7.2(fedora16) and python2.7.2+(ubuntu). Related discuss on
python issue tracker:
    http://bugs.python.org/issue2320
    It is similar to what I observed, program hangs on a thread calling
subprocess pipe. Issue conclusion is that, it is fixed in python 3.2 but not python 2.7. My test case is that one thread hanging at
subprocess pipe call while another thread call start(). So more
validation is needed on python 3.2 to see if it covers the situation.


Test .py file content:

#! /usr/bin/python

import subprocess
import threading
import time
import random
import logging

myLogger = logging.getLogger('My')
sleeptime = 0

global test_cycle
test_cycle = 200
global result
result = 0

def execCmd(command):
    infile = subprocess.PIPE
    outfile = subprocess.PIPE
    err = subprocess.PIPE
p = subprocess.Popen(command, stdin=infile, stdout=outfile, stderr=err, close_fds=True)
    #p = subprocess.Popen(command, stdin=subprocess.PIPE)
    (out, err) = p.communicate()
    myLogger.info("cmd is %s, out is %s, err is %s.", command, out, err)


class StorageThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        global result
        thread_c = 0
        while thread_c < test_cycle:
            thread_c += 1
            myLogger.info("call pipe for %d times.", thread_c)
            execCmd("cat")
            ran = random.random()
            #time.sleep(ran)

        print "@@@@@@@thread all excuted!"
        result = 1


class StatsThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        myLogger.info("simple thread started")

#main
formatstr = "%(threadName)s::%(levelname)s::%(asctime)s::%(module)s::%(lineno)d::%(name)s::(%(funcName)s) %(message)s"
logging.basicConfig(format=formatstr, level=logging.DEBUG)
handler = logging.StreamHandler()
logging.addLevelName(5, 'TRACE')
logging.TRACE = 5
#logging.root.handlers.append(logging.StreamHandler())
#handler = logging.FileHandler("/var/log/vdsm/testlog.txt")
#logging.root.handlers.append(handler)


storage_thread = StorageThread()
storage_thread.start()

thread_m = 0
while thread_m < test_cycle:
    new_thread = StatsThread()
    new_thread.start()
    #new_thread.join()

    ran = random.random()
    #time.sleep(ran)
    thread_m += 1

print "waiting for thread calling pipe complete"
while result == 0:
    time.sleep(0.2)
print "succeed!"
print "sleeping"
#time.sleep(1)


#! /usr/bin/python

import subprocess
import threading
import time
import random
import logging

myLogger = logging.getLogger('My')
sleeptime = 0

global test_cycle
test_cycle = 200
global result
result = 0

def execCmd(command):
    infile = subprocess.PIPE
    outfile = subprocess.PIPE
    err = subprocess.PIPE
    p = subprocess.Popen(command, stdin=infile, stdout=outfile, stderr=err, 
close_fds=True)
    #p = subprocess.Popen(command, stdin=subprocess.PIPE)
    (out, err) = p.communicate()
    myLogger.info("cmd is %s, out is %s, err is %s.", command, out, err)


class StorageThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        global result
        thread_c = 0
        while thread_c < test_cycle:
            thread_c += 1
            myLogger.info("call pipe for %d times.", thread_c)
            execCmd("cat")
            ran = random.random()
            #time.sleep(ran)

        print "@@@@@@@thread all excuted!"
        result = 1


class StatsThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        myLogger.info("simple thread started")

#main
formatstr = 
"%(threadName)s::%(levelname)s::%(asctime)s::%(module)s::%(lineno)d::%(name)s::(%(funcName)s)
 %(message)s"
logging.basicConfig(format=formatstr, level=logging.DEBUG)
handler = logging.StreamHandler()
logging.addLevelName(5, 'TRACE')
logging.TRACE = 5
#logging.root.handlers.append(logging.StreamHandler())
#handler = logging.FileHandler("/var/log/vdsm/testlog.txt")
#logging.root.handlers.append(handler)


storage_thread = StorageThread()
storage_thread.start()

thread_m = 0
while thread_m < test_cycle:
    new_thread = StatsThread()
    new_thread.start()
    #new_thread.join()

    ran = random.random()
    #time.sleep(ran)
    thread_m += 1

print "waiting for thread calling pipe complete"
while result == 0:
    time.sleep(0.2)
print "succeed!"
print "sleeping"
#time.sleep(1)
_______________________________________________
vdsm-devel mailing list
vdsm-devel@lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/vdsm-devel

Reply via email to