Python multi-threading questions

Asked 1 years ago, Updated 1 years ago, 323 views

I'm trying to implement multi-threading in Python.

When the thread of t_0 enters the function, it is held continuously at while 1. The code that then executes the t_1 thread does not move on.

If the first thread doesn't end when I run it, does the next thread not run?

def a():
    _compare()

def b():
    _refresh()

if __name__ == '__main__':
    t_0 = threading.Thread(target=a(), name='t0', deamon=True)
    t_1 = threading.Thread(target=b(), name='t1' , deamon=True)

def _compare():
    fCount =_totalCount() #Compared to
    try:
        while 1:
            cCount = _totalCount()
            if fCount == cCount: 
                time.sleep(10) #If the comparison is the same, wait 10 seconds
            elif fCount < cCount:
                _printChange(cCount)
                fCount = cCount
                time.sleep(10)
            else:
                _compare()
                time.sleep(10)
    except:
        Alarm._exceptAlarm()

python multithreading

2023-03-07 08:36

1 Answers

threading.Thread(target=a(), name='t0', deamon=True) -- X

threading.Thread(target=a, name='t0', deamon=True) -- O


2023-03-07 14:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.