Questions regarding Python Thread Module.

Asked 2 years ago, Updated 2 years ago, 76 views

I'm making a chat program with Python and I'm in trouble. You need to turn socket receive and send together with the thread, but if you turn input to the thread, other threads will also stop. If you enter input, the sending thread will turn again and stop at input.

import threading
import time

lock = threading.Lock()

def inp():
    while True:
        a = input ('input:')
        print(a)
        time.sleep(1)

def pr():
    while True:
        print('dd\n')
        time.sleep(1)

inp()
t = threading.Thread(target = pr)
t.start()

This is a code that I made to test the thread module, and here I found that input stops other threads. Please tell me I made a mistake.

threading thread

2022-09-22 19:05

1 Answers

Take your time to review the code.

Invoke the inf function before generating the thread.

The inf function consists of infinite loops.

Naturally, threads would not have been created, and only the while loop within the inf would be repeated.


2022-09-22 19:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.