From: <bob...@ai...> - 2008-01-14 00:05:55
|
-----Original Message----- From: bob...@ai... To: bil...@gm... Sent: Sun, 13 Jan 2008 3:34 pm Subject: Re: [Jython-dev] Why select module but not asyncore? Hi Giampaolo, Ah, the map is not empty, though.? The map exists and the socket is in it, so the poll function is called.? But, the file descriptor is empty (or None).? So it makes it through the asyncore loop.? The File is not watchable error happens in the Jython version of select (select.py).? The place where it is triggered is in a function right at the top of the module called _getselectable(). ? def _getselectable(selectable_object): ??? for method in ['getchannel', 'fileno']: ??????? try: ??????????? channel = getattr(selectable_object, method)() ??????????? if channel and not isinstance(channel, java.nio.channels.SelectableChannel): ??????????????? raise TypeError("Object '%s' is not watchable" % selectable_object,?????????????? ?????????????????????????????????????????????????????? errno.ENOTSOCK) ??????????? return channel ??????? except: ??????????? pass ??? raise TypeError("Object '%s' is not watchable" % selectable_object, errno.ENOTSOCK) Since there is no File Descriptor in the map, the function raises the TypeError() at the end of the function. It seems to be a rather long and complicated story, and Alan or someone please correct me if I make a mistake,? but Java does not have the same notion of file descriptors that c and unix have.? So Jython uses the underlying channel for the file descriptor for a socket.? In Java, you can have a socket without a channel so there will be cases where you have a socket without a file descriptor.? Jython now since 2.2 will (always? - Alan?) have a file descriptor for sockets.? So, what my initial fix tried to do was correct the problem by setting the channel for the socket to _fileno and put it in the map in add_channel in asyncore.? I do not know if this is the proper place to make this update. This is the init part of my test asyncore ServerSocket class: class MainServerSocket(asyncore.dispatcher): ??? def __init__(self, port): ??????? asyncore.dispatcher.__init__(self) ??????? self.create_socket(socket.AF_INET, socket.SOCK_STREAM) ??????? self.bind(('',port)) ??????? self.listen(5) If you put asyncore in the current Jython 2.2.1 code, this class will create a map with a socket and None for the file descriptor.? To me, the key is where do we update the map with the File Descriptor. But trace the flow, you will see that the map exists, and is not empty, but there is no file descriptor. ?- Bob -----Original Message----- From: Giampaolo Rodola' <bil...@gm...> To: bob...@ai... <bob...@ai...>; jyt...@li... Sent: Sun, 13 Jan 2008 2:36 pm Subject: Re: [Jython-dev] Why select module but not asyncore? > Hi Giampaolo, Hi there Bob > I have just spent some time on this as well. The particular error that you > are getting is the same error that I was receiving. Alan told me and I have > since verified that it is because the file descriptor for the socket is not > in the asyncore socket map. No man, I'm sure this is not true. If the socket_map dictionary is empty the poll() function is not even called. Take a look at here: def loop(timeout=30.0, use_poll=False, map=None, count=None): if map is None: map = socket_map if use_poll and hasattr(select, 'poll'): poll_fun = poll2 else: poll_fun = poll if count is None: while map: poll_fun(timeout, map) else: while map and count > 0: poll_fun(timeout, map) count = count - 1 > So, I have modified asyncore in my testing to > set self._fileno = self.socket.fileno in dispatcher add_channel method like > this: > > > def add_channel (self, map=None): > print 'adding channel:', self, self.fileno > if map is None: > map=socket_map > self._fileno = self.fileno > map [self._fileno] = self > print map Sorry but I can't see any difference from the original implementation. This is exactly what add_channel() method already does. 2008/1/12, bob...@ai... <bob...@ai...>: > > Hi Giampaolo, > > I have just spent some time on this as well. The particular error that you > are getting is the same error that I was receiving. Alan told me and I have > since verified that it is because the file descriptor for the socket is not > in the asyncore socket map. So, I have modified asyncore in my testing to > set self._fileno = self.socket.fileno in dispatcher add_channel method like > this: > > > def add_channel (self, map=None): > print 'adding channel:', self, self.fileno > if map is None: > map=socket_map > self._fileno = self.fileno > map [self._fileno] = self > print map > > However, this did not fix the problem. I am not sure why yet. But this > could give you a start to solve the problem. It actually looks like > asyncore is not too far away from working. I hope this helps you. I do > not claim expertise in either asyncore or the jython implementation of > select, but I have worked with it some and could help you get started. > > - Bob > > > > > > > -----Original Message----- > From: Giampaolo Rodola' <bil...@gm...> > To: jyt...@li... > Sent: Sat, 12 Jan 2008 11:27 am > Subject: [Jython-dev] Why select module but not asyncore? > > > > Hi all, > > I noticed that the 2.2 version finally included the select module but > > I also noticed that asyncore and asynchat modules aren't available > > yet. > > > > Just for the heck of it I've tried to use the cPython asyncore.py but > > this is the error I get when I try to run an asyncore-based module of > > mine: > > > > c:\jython2.2.1>jython.bat ftpserver.py > > Serving FTP on 0.0.0.0:21 > > Traceback (innermost last): > > File "ftpserver.py", line 2374, in ? > > File "ftpserver.py", line 2370, in test > > File "ftpserver.py", line 2284, in serve_forever > > File "C:\jython2.2.1\Lib\asyncore.py", line 191, in loop > > File "C:\jython2.2.1\Lib\asyncore.py", line 121, in poll > > File "C:\jython2.2.1\Lib\select.py", line 171, in native_select > > File "C:\jython2.2.1\Lib\select.py", line 90, in register > > File "C:\jython2.2.1\Lib\select.py", line 54, in _getselectable > > TypeError: ("Object 'None' is not watchable", 88) > > > > > > Is there a reason why asyncore.py shouldn't work with select? > > I don't know much about jython but I'm experienced with asyncore, so I > > would happy to give an help, if needed. > > > > ------------------------------------------------------------------------- > > Check out the new SourceForge.net Marketplace. > > It's the best place to buy or sell services for > > just about anything Open Source. > > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > > _______________________________________________ > > Jython-dev mailing list > > Jyt...@li... > > https://lists.sourceforge.net/lists/listinfo/jython-dev > > > ________________________________ > More new features than ever. Check out the new AIM(R) Mail! > More new features than ever. Check out the new AIM(R) Mail! ________________________________________________________________________ More new features than ever. Check out the new AIM(R) Mail ! - http://webmail.aim.com |