python2.6 epoll.modify failed to unregister events ?
Hi Guys, I have encountered an epoll issues. On the server side, I use epoll.poll() to wait for events, when there is a socket which has EPOLLIN/EPOLLUP events, I first try to read the socket (I did this coz it says EPOLLIN ready, I might think it has some data in its recv queue). After reading 0 length data, the code thinks the peer shutdown its socket, so it notifies the epoll that it doesn't care any events for this socket anymore by calling epoll.modify(sock, 0). But this call seems failed to function, coz when I did another round of epoll.poll(), the socket is still ready for EPOLLUP. My understanding for epoll Linux interface is that it should work if we pass no events when calling epoll_ctl. Steps to reproduce this problem. Open up two consoles, one for client, one for server. Input the following code in the two consoles by the following order. --- Server --- >>> import socket >>> accept_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >>> accept_socket.setblocking(False) >>> accept_socket.bind(('10.5.6.10', )) >>> accept_socket.listen(socket.SOMAXCONN) >>> import select >>> ep = select.epoll() >>> ep.register(accept_socket.fileno(), select.EPOLLIN) client --- >>> import socket >>> st = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >>> st.connect(('10.5.6.10', )) Server >>> ep.poll() [(4, 1)] >>> sock, peer_addr = accept_socket.accept() >>> ep.register(sock, select.EPOLLIN) Client --- >>> st.send('ahello') 6 Server --- >>> ep.poll() [(6, 1)] >>> sock.recv(1024) 'ahello' >>> sock.shutdown(socket.SHUT_WR) Client --- >>> st.recv(1024) '' >>> st.shutdown(socket.SHUT_WR) Server >>> ep.poll() [(6, 17)] >>> sock.recv(1024) '' >>> ep.modify(sock, 0) <= I am saying, i don't care any events for the sock >>> ep.poll() <= but epoll still return the event for this sock [(6, 16)] >>> ep.poll() [(6, 16)] >>> ep.modify(sock, 0) >>> ep.poll() [(6, 16)] -- http://mail.python.org/mailman/listinfo/python-list
Exception in thread QueueFeederThread (most likely raised during interpreter shutdown)
Hi Guys, I am using the multiprocessing module. The following code snippet occasionally throws the "Exception in thread QueueFeederThread (most likely raised during interpreter shutdown)" exception. I searched google for the cause, someone says there are some issues with the multiprocessing.Queue (need do some sleep at where the queue is used). Could you please shed your light here, what is wrong, how can I use the multiprocess correctly ? Thanks very much ! The python version is 2.6 and on Win7 x64 OS. -- from multiprocessing import Process,Queue def listTest(q): print q.get() def queueTest(): q = Queue() q.put([1,2,3,4,5,6]) p = Process(target=listTest,args=(q,)) p.start() p.join() if __name__=='__main__': queueTest() Exception in thread QueueFeederThread (most likely raised during interpreter shutdown): -- http://mail.python.org/mailman/listinfo/python-list
Re: Exception in thread QueueFeederThread (most likely raised during interpreter shutdown)
On Thursday, February 21, 2013 2:20:41 AM UTC+8, MRAB wrote: > On 2013-02-20 08:26, Ziliang Chen wrote: > Hi Guys, > I am using the > multiprocessing module. The following code snippet occasionally throws the > "Exception in thread QueueFeederThread (most likely raised during interpreter > shutdown)" exception. > > I searched google for the cause, someone says there > are some issues with the multiprocessing.Queue (need do some sleep at where > the queue is used). > > Could you please shed your light here, what is wrong, > how can I use the multiprocess correctly ? > > Thanks very much ! > > The > python version is 2.6 and on Win7 x64 OS. > > -- > from > multiprocessing import Process,Queue > > def listTest(q): > print q.get() > > > def queueTest(): > q = Queue() > q.put([1,2,3,4,5,6]) > p = > Process(target=listTest,args=(q,)) > p.start() > p.join() > > if > __name__=='__main__': > queueTest() > > Exception in thread QueueFeederThread > (most likely raised during interpreter shutdown): > I think it may be a race > condition. When I tried it, sometimes it failed, sometimes it didn't. It seemed to be better behaved when I put a small sleep at the end to delay the main process exiting. Thanks, MRAB! Yeah, I saw such kind of workaround after googling. But seriously, why is there a race condition here ? Is there any misuse of queue here ? -- http://mail.python.org/mailman/listinfo/python-list
yield expression
Hi folks, When I am trying to understand "yield" expression in Python2.6, I did the following coding. I have difficulty understanding why "val" will be "None" ? What's happening under the hood? It seems to me very time the counter resumes to execute, it will assign "count" to "val", so "val" should NOT be "None" all the time. Thanks ! code snippet: def counter(start_at=0): count = start_at while True: val = (yield count) if val is not None: count = val else: print 'val is None' count += 1 -- http://mail.python.org/mailman/listinfo/python-list
yield expression
Hi folks, When I am trying to understand "yield" expression in Python2.6, I did the following coding. I have difficulty understanding why "val" will be "None" ? What's happening under the hood? It seems to me very time the counter resumes to execute, it will assign "count" to "val", so "val" should NOT be "None" all the time. Thanks ! code snippet: def counter(start_at=0): count = start_at while True: val = (yield count) if val is not None: count = val else: print 'val is None' count += 1 -- http://mail.python.org/mailman/listinfo/python-list
yield expression
Hi folks, When I am trying to understand "yield" expression in Python2.6, I did the following coding. I have difficulty understanding why "val" will be "None" ? What's happening under the hood? It seems to me very time the counter resumes to execute, it will assign "count" to "val", so "val" should NOT be "None" all the time. Thanks ! code snippet: def counter(start_at=0): count = start_at while True: val = (yield count) if val is not None: count = val else: print 'val is None' count += 1 -- http://mail.python.org/mailman/listinfo/python-list
Re: yield expression
On Monday, February 25, 2013 8:51:28 AM UTC+8, Oscar Benjamin wrote: > On 25 February 2013 00:39, Ziliang Chen wrote: > > > Hi folks, > > > When I am trying to understand "yield" expression in Python2.6, I did the > > following coding. I have difficulty understanding why "val" will be "None" > > ? What's happening under the hood? It seems to me very time the counter > > resumes to execute, it will assign "count" to "val", so "val" should NOT be > > "None" all the time. > > > > > > Thanks ! > > > > > > code snippet: > > > > > > def counter(start_at=0): > > > count = start_at > > > while True: > > > val = (yield count) > > > if val is not None: > > > count = val > > > else: > > > print 'val is None' > > > count += 1 > > > > The value of the yield expression is usually None. yield only returns > > a value if the caller of a generator function sends one with the send > > method (this is not commonly used). The send method supplies a value > > to return from the yield expression and then returns the value yielded > > by the next yield expression. For example: > > > > >>> g = counter() > > >>> next(g) # Need to call next() once to suspend at the first yield call > > 0 > > >>> g.send('value for count') # Now we can send a value for yield to return > > 'value for count' > > > > > > Oscar Thanks Oscar ! I am cleared. Only when "send" is used to feed "yield" a new value, the "yield" expression has none "None", otherwise, "yield" expression has "None" value. -- http://mail.python.org/mailman/listinfo/python-list