[python-win32] Welcome to the "python-win32" mailing list

Tim Roberts timr at probo.com
Mon Dec 29 19:23:09 CET 2008


Joshua Lim wrote:
> Hi everyone,
>
> I'm new to python or C.  I've been trying to get open source pyrad, a
> socket radius python app, to work on win32, and encountered an error:
>
> Traceback (most recent call last):
>   File "C:\Python25\pyrad\example\server.py", line 36, in <module>
>     srv.Run()
>   File "C:\Python25\pyrad\example\server.py", line 256, in Run
>
> AttributeError: 'module' object has no attribute 'poll'
>
> A quick Google revealed that the error has something to do with Linux
> poll not working under windows.  I searched Pyrad code, server.py,
> line 256, and this brought up the following:
>
>     def Run(self):
>         """Main loop.
>
>         This method is the main loop for a RADIUS server. It waits
>         for packets to arrive via the network and calls other methods
>       &nbs p; to process them.
>         """
>         self._poll=select.poll()
>         self._fdmap={}
>         self._PrepareSockets()
>
>         while 1:
>             for (fd, event) in self._poll.poll():
>                 if event==select.POLLIN:
>                     try:
>                         fdo=self._fdmap[fd]
>                         self._ProcessInput(fdo)
>                     exc ept ServerPacketError, err:
>                                                 logger.info("Dropping
> packet: " + str(err))
>                     except packet.PacketError, err:
>                         logger.info("Received a broken packet: " +
> str(err))
>                 else:
>                                         logger.e rror("Unexpected
> event in server main loop")
>
>
>
> As i understand, i need to change the code to use select.select().  I
> tried replacing "select.poll()" with "select.select()" but got a new
> error:
>
> TypeError: select expected at least 3 arguments, got 0
>
> What should i do?  Would appreciate any tip.  :)

Well, "select" is not just a drop-in replacement for "poll", although it
can serve the same function.  Without looking at the rest of the source,
you probably want something like this:

   def Run( self ):
        self._fdmap = {}
        self._PrepareSockets()
        while 1:
            fdi = select.select( self._fdmap, [], [] )[0]
            if fdi:
                self._ProcessInput( fdi[0] )
            else:
                logger.error( "select returned empty." )

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list