Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python threading only launching one extra thread

import socket
import thread
s = socket.socket(
    socket.AF_INET, socket.SOCK_STREAM)
s.connect(("server", 6661))
def recv():
    while 1:
        print(s.recv(1024))
def send():
    while 1:
        msg = raw_input("> ")
        s.send(msg)
thread.start_new_thread(recv())
thread.start_new_thread(send())

Why does the code not run after thread recv() - I can't see where it should hang

like image 504
AB49K Avatar asked Mar 22 '23 20:03

AB49K


1 Answers

Adjust as follow:

thread.start_new_thread(recv, ())
thread.start_new_thread(send, ())

By appending () right after the function name, you call recv and send in main thread, not in new thread.

like image 77
falsetru Avatar answered Apr 02 '23 19:04

falsetru