[New-bugs-announce] [issue14016] Usage of socket.sendall() in multiple threads

Srikantha Kadur report at bugs.python.org
Tue Feb 14 20:12:27 CET 2012

New submission from Srikantha Kadur <srikanthkadur at gmail.com>:

Here is my code.

        CliSock, addr = ServSocket.accept()
        print 'DataPortServ:Connected by', addr
	data.DataSendSock = CliSock
	for cnt in range(data.ThreadCnt):
            SessionId = startSessionId + SessionIdCnt* cnt      

    #here i use socket.sendall
     while True:
        if ( 3 != data.bRunFlag):     
           if (len(data.AddedEvents) != 0) | (len(data.AddedReasons) != 0):
     	       for EventCnt in range(StartEvent,StopEvent):

My application is a server and it accepts connection from the client on a port and start sending some messages to the client. While sending messages i use multiple threads for the same socket based on required traffic. 

I do not modify any global variables but i read only global variables.But at high Loads my messages are being corrupted, here is the snippet of the corruption

actual message should have been 

instead im getting

so here is my Q:
Do i need to lock the socket before sending inside the threads or Python modules will take care of it? Please suggest.

components: 2to3 (2.x to 3.x conversion tool)
messages: 153361
nosy: srikadur
priority: normal
severity: normal
status: open
title: Usage of socket.sendall() in multiple threads
type: behavior

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list