File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed
Tests/modules/network_related Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -533,22 +533,27 @@ def test_misc(self):
533533 def test_makefile_refcount (self ):
534534 "Ensures that the _socket stays open while there's still a file associated"
535535
536- global PORT
536+ global GPORT
537+ if 'GPORT' in globals ():
538+ del GPORT
537539 def echoer ():
538- global PORT
540+ global GPORT
539541 s = socket .socket ()
540542 s .setsockopt (socket .SOL_SOCKET , socket .SO_REUSEADDR , 1 ) # prevents an "Address already in use" error when the socket is in a TIME_WAIT state
541543 s .settimeout (15 ) # prevents the server from staying open if the client never connects
542544 s .bind (('localhost' , 0 ))
543- PORT = s .getsockname ()[1 ]
545+ GPORT = s .getsockname ()[1 ]
544546 s .listen (5 )
545547 (s2 , ignore ) = s .accept ()
546548 s2 .send (s2 .recv (10 ))
547549
548550 _thread .start_new_thread (echoer , ())
549- time .sleep (1 )
551+ for _ in range (20 ):
552+ time .sleep (1 )
553+ if 'GPORT' in globals ():
554+ break
550555 s = socket .socket ()
551- s .connect (('localhost' , PORT ))
556+ s .connect (('localhost' , GPORT ))
552557 f1 = s .makefile ('r' )
553558 f2 = s .makefile ('w' )
554559 s .close ()
You can’t perform that action at this time.
0 commit comments