多线程和原始输入问题python

时间:2017-03-22 16:04:43

标签: python multithreading

所以你运行它会提示用户输入密码,这样你就可以输入4位数的引脚,它会打印出名称并将其添加到列表中。

import time
import datetime
import threading
from threading import Thread

StudentInfo={
1126:'Abel',
1134:'Diego',
}

flag = True

number=StudentInfo.keys()
name=StudentInfo.values()
StudentPresent=[]

def func1():
    global flag
    global StudentPresent
    while flag == True:
        StudentID = int(raw_input("What student are you? "))
        if StudentID in number:
            here = StudentInfo.get(StudentID)
            print here
            StudentPresent.append(here)
            print StudentPresent       
        else:
            print "Not in our system, check with Admin"
        if StudentID == 9999:
            flag= False
            print flag


#if __name__ == '__main__':
    #Thread(target = func1).start()

现在,一旦我从最后两行中取出注释标签,它就会运行该功能,并且不允许用户输入其号码。我脱掉了第二个线程函数,因为它工作得很好。它只是在指定的时间发送电子邮件。所以出于问题的目的,我把所有这些都拿出来,因为这是我所有问题的根源。

import time
import datetime
import threading
from threading import Thread

StudentInfo={
1126:'Abel',
1134:'Diego',
}

flag = True

number=StudentInfo.keys()
name=StudentInfo.values()
StudentPresent=[]

def func1():
    global flag
    global StudentPresent
    while flag == True:
        StudentID = int(raw_input("What student are you? "))
        if StudentID in number:
            here = StudentInfo.get(StudentID)
            print here
            StudentPresent.append(here)
            print StudentPresent       
        else:
            print "Not in our system, check with Admin"
        if StudentID == 9999:
            flag= False
            print flag


if __name__ == '__main__':
    Thread(target = func1).start()

0 个答案:

没有答案