@@ -64,11 +64,11 @@ def _removeSocket(self, socket) :
6464 with self ._opLock :
6565 if socketno in self ._asyncSockets :
6666 del self ._asyncSockets [socketno ]
67- if socket in self ._readList :
68- self ._readList .remove (socket )
69- if socket in self ._writeList :
70- self ._writeList .remove (socket )
71- return True
67+ if socket in self ._readList :
68+ self ._readList .remove (socket )
69+ if socket in self ._writeList :
70+ self ._writeList .remove (socket )
71+ return True
7272 return False
7373
7474 # ------------------------------------------------------------------------
@@ -98,18 +98,17 @@ def _sendUDPSockEvent(self) :
9898
9999 def _processWaitEvents (self ) :
100100
101- def jobExceptionalCondition (asyncSocket ) :
102- asyncSocket .OnExceptionalCondition ()
103- self ._socketListRemove (asyncSocket . GetSocketObj () , self ._handlingList )
101+ def jobExceptionalCondition (args ) :
102+ args [ 0 ] .OnExceptionalCondition ()
103+ self ._socketListRemove (args [ 1 ] , self ._handlingList )
104104
105- def jobReadyForWriting (asyncSocket ) :
106- asyncSocket .OnReadyForWriting ()
107- self ._socketListRemove (asyncSocket . GetSocketObj () , self ._handlingList )
105+ def jobReadyForWriting (args ) :
106+ args [ 0 ] .OnReadyForWriting ()
107+ self ._socketListRemove (args [ 1 ] , self ._handlingList )
108108
109- def jobReadyForReading (asyncSocket ) :
110- s = asyncSocket .GetSocketObj ()
111- asyncSocket .OnReadyForReading ()
112- self ._socketListRemove (asyncSocket .GetSocketObj (), self ._handlingList )
109+ def jobReadyForReading (args ) :
110+ args [0 ].OnReadyForReading ()
111+ self ._socketListRemove (args [1 ], self ._handlingList )
113112
114113 self ._processing = True
115114
@@ -141,23 +140,23 @@ def jobReadyForReading(asyncSocket) :
141140 if self ._socketListAdd (sock , self ._handlingList ) :
142141 if socketsList is rd :
143142 if self ._microWorkers :
144- self ._microWorkers .AddJob (jobReadyForReading , asyncSocket )
143+ self ._microWorkers .AddJob (jobReadyForReading , ( asyncSocket , sock ) )
145144 else :
146145 jobReadyForReading (asyncSocket )
147146 elif socketsList is wr :
148147 self ._socketListRemove (sock , self ._writeList )
149148 if self ._microWorkers :
150- self ._microWorkers .AddJob (jobReadyForWriting , asyncSocket )
149+ self ._microWorkers .AddJob (jobReadyForWriting , ( asyncSocket , sock ) )
151150 else :
152151 jobReadyForWriting (asyncSocket )
153152 else :
153+ self ._removeSocket (sock )
154154 if self ._microWorkers :
155- self ._microWorkers .AddJob (jobExceptionalCondition , asyncSocket )
155+ self ._microWorkers .AddJob (jobExceptionalCondition , ( asyncSocket , sock ) )
156156 else :
157157 jobExceptionalCondition (asyncSocket )
158158 else :
159- self ._socketListRemove (sock , self ._readList )
160- self ._socketListRemove (sock , self ._writeList )
159+ self ._removeSocket (sock )
161160 sock .close ()
162161 sec = perf_counter ()
163162 if sec > timeSec + XAsyncSocketsPool ._CHECK_SEC_INTERVAL :
@@ -166,6 +165,7 @@ def jobReadyForReading(asyncSocket) :
166165 if asyncSocket .ExpireTimeSec and \
167166 timeSec > asyncSocket .ExpireTimeSec :
168167 asyncSocket ._close (XClosedReason .Timeout )
168+ self ._removeSocket (asyncSocket .GetSocketObj ())
169169 except :
170170 pass
171171
@@ -1194,7 +1194,10 @@ def _workerThreadFunc(self, arg) :
11941194 jobFunc , jobArg = self ._jobs .pop (0 )
11951195 except :
11961196 self ._workersLock .acquire ()
1197- self ._workersLock .release ()
1197+ try :
1198+ self ._workersLock .release ()
1199+ except :
1200+ pass
11981201 if jobFunc :
11991202 with self ._criticalLock :
12001203 self ._jobsPrcCount += 1
0 commit comments