在上面代码的基础上,两个线程的优先级分别设置1和5。打印出代码
时间: 2024-03-10 13:43:37 浏览: 24
这是您的代码:
```python
import threading
def print_nums():
for i in range(10):
print(i)
def print_letters():
for i in range(65, 75):
print(chr(i))
thread1 = threading.Thread(target=print_nums)
thread2 = threading.Thread(target=print_letters)
thread1.daemon = True
thread2.daemon = True
thread1.start()
thread2.start()
thread1.join()
thread2.join()
```
以下是将线程优先级设置为1和5的修改后的代码:
```python
import threading
def print_nums():
for i in range(10):
print(i)
def print_letters():
for i in range(65, 75):
print(chr(i))
thread1 = threading.Thread(target=print_nums)
thread2 = threading.Thread(target=print_letters)
thread1.daemon = True
thread2.daemon = True
thread1.priority = 1
thread2.priority = 5
thread1.start()
thread2.start()
thread1.join()
thread2.join()
```
请注意,线程优先级的设置可能因操作系统而异。在某些系统上,这种设置可能不会产生任何影响。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)