并行写入两个python文件

2024-05-29 07:57:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我只是想在线程的帮助下并行地写两个文件。你知道吗

def dmesg (i):

    cmd = 'dmesg'
    print cmd
    (status, cmd_out) = commands.getstatusoutput(cmd)
    fil = open('dmesg_logs', 'w')
    fil.write(cmd_out)
    fil.close()

def dump (i):

    cmd = 'lsmod'
    print cmd
    (status, cmd_out) = commands.getstatusoutput(cmd)
    fil = open('logs', 'w')
    fil.write(cmd_out)
    fil.close()
if __name__ == "__main__":

    t1 = threading.Thread(target = dmesg, args=(0,))
    t1.start()
    t2 = threading.Thread(target = dump, args=(0,))
    t2.start()
    while True : 
        "My own code"

这里我的问题是日志文件不是在线程2中创建的。我能知道我做错了什么吗?你知道吗


Tags: 文件cmdclosedefstatusopenoutdump

热门问题