asyncore.poll() question
chad
cdalten at gmail.com
Sat Oct 16 13:35:27 EDT 2010
On Oct 16, 6:47 am, Lucasm <lordlucr... at gmail.com> wrote:
> On 16 Okt, 15:31, chad <cdal... at gmail.com> wrote:
>
>
>
> > At the following url..
>
> >http://www.nightmare.com/medusa/programming.html
>
> > The author has the following code for a simple HTTP client
>
> > #!/usr/bin/python
>
> > import asyncore
> > import socket
> > import string
>
> > class http_client (asyncore.dispatcher):
>
> > def __init__ (self, host, path):
> > asyncore.dispatcher.__init__ (self)
> > self.path = path
> > self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
> > self.connect ((host, 80))
>
> > def handle_connect (self):
> > self.send ('GET %s HTTP/1.0\r\n\r\n' % self.path)
>
> > def handle_read (self):
> > data = self.recv (8192)
> > print data
>
> > def handle_write (self):
> > pass
>
> > if __name__ == '__main__':
> > import sys
> > import urlparse
> > for url in sys.argv[1:]:
> > parts = urlparse.urlparse (url)
> > if parts[0] != 'http':
> > raise ValueError, "HTTP URL's only, please"
> > else:
> > host = parts[1]
> > path = parts[2]
> > http_client (host, path)
> > asyncore.loop()
>
> > Right after that, the author states the following...
>
> > " A really good way to understand select() is to put a print statement
> > into the asyncore.poll() function:
>
> > [...]
> > (r,w,e) = select.select (r,w,e, timeout)
> > print '---'
> > print 'read', r
> > print 'write', w
> > [...]
>
> > Each time through the loop you will see which channels have fired
> > which events.
> > "
>
> > How the heck do I modify the code put the print statement into the
> > asyncore.poll() function?
>
> > Chad
>
> Hi,
>
> You can find the file in your Python directory, in my case /usr/lib/
> Python2.6/asyncore.py. You should delete the .pyc file to make sure it
> is recompiled. And you will need root access :).
>
> Lucas
I just did that...
[root at localhost python2.6]# ls -al asyncore.py
-rw-r--r-- 1 root root 19262 Oct 16 10:22 asyncore.py
[root at localhost python2.6]# ls -al asyncore.pyc
-rw-r--r-- 1 root root 16773 Oct 16 10:26 asyncore.pyc
[root at localhost python2.6]# ls -al asyncore.pyo
-rw-r--r-- 1 root root 16773 Oct 16 10:42 asyncore.pyo
[root at localhost python2.6]#
And nothing happened. Ideas?
More information about the Python-list
mailing list