no buffer space available error

sebastien s.thuriez at laposte.net
Wed May 15 13:41:34 EDT 2002


Hi,

I have looked around to see more precisely where the problem could
lay.

The problem may not be directly the number of thread. I depends on the
number of thread and on the sleeping time I can put in my code. The
more I sleep the more threads I can open.

I have simplified the program so that you can count the number of
socket open at a time.

1) I have checked that all the sockets open are closed (see the code)

2) There is a direct relation between the number of socket open and
the sleeping time that I use : if you open about 15 sockets at the
same time it is OK as far as the time.sleep(10). 10 sockets can be
open as fas as time.sleep(5)


3) Over value that does not permit to remove the NO BUFFER SPACE
AVAILABLE  for example 3 sockets and time.sleep(1).

Below is the code to show that it is quit simple !!!

I hope that someone see what goes wrong .

Regards. Sebastien

here is the code :
 -----------------------------------------------------------
import select
import sys, string, os
import socket
import time
import thread
from pprint import pprint
import threading
import gc

FTP_PORT = 21


debug=[]
error_control=[]
no_buffer_space_available=[]
debugg2=[]
not_closed=[]
socket_active=[]

def control(hostname):

    reponse='non'
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.setblocking(0)
    socket_active.append(hostname)

    print "connect : ",hostname
    try :
        s.connect((hostname,FTP_PORT))
    except socket.error, why :
        debug.append((hostname,why[1]))
        if why[1] <> "The socket operation could not complete without
blocking":
            print 'cannot connect...',hostname, "why = ",why[1]
            
    try :
        s.close()
        socket_active.remove(hostname)
        print "nb socket ",len(socket_active)
    except :
        not_closed.append(hostname)
        print "not closed ",not_closed
        print "problemes de s.close"
            
    return reponse


def maine():

    global identifiant_thread

    max_thread=25
    
    number_thread=0 #initialisation
    
    for indice in range(1,255): #to scan the network
        adresse="192.168.15."+str(indice)
        if number_thread>max_thread:
            print "question_ftp_threaded :  number thread > max thread
:sleeping"
            time.sleep(10)
            number_thread=0
        else:
            number_thread=number_thread+1
        try :
            thread.start_new_thread(control,(adresse,))
        except:
            print "probleme de lancement de threads"
    print not_closed

    file=open ("c:\debug.txt","w")
    for hostname, error_message in debug:
        file.write(hostname+ " "+error_message+"\n")
    file.close()
    print debug
    
    return

def main() :    

    debug=[]
    ftp_existe=[]
    maine()
    print "fin"


main()    

-------------------------------------------------------------------------

Kragen Sitaker <kragen at pobox.com> wrote in message news:<83lmangql2.fsf at panacea.canonical.org>...
> s.thuriez at laposte.net (sebastien) writes:
> > I am trying a program that [uses a lot of sockets]
> > What do I do wrong ? As I get the message can I flush the buffer ?
> > I am running python 2.1.1 on Windows Me and NT.
> 
> Why don't you try running your program on a Linux machine instead?
> You might run into some trouble with limits on the number of open file
> descriptors, a limit you can usually increase to 1024 with the
> 'ulimit' or 'limit' command.
> 
> Also, try limiting the number of simultaneous open sockets.



More information about the Python-list mailing list