Async callback in python

2006-12-04 Thread Linan
Hi,

In javascript, code could be written like this:

...

var _p=XMLHttpRequest();
_p.open('GET',url,true);
_p.send(null);
_p.onreadystateChange=function(){
if(_p.readyState==4)
cb(_p.responseText);
}
...

This basic AJAX code allows function to be called when it's invoked,
without blocking the main process. There is same library asyncore in
python. However, I can't validate it's asynchronous through code:
class T(asyncore.dispatcher):
def __init__(self,host,url):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((host,80))
self.url='GET %s HTTP/1.0\r\n\r\n' % url

def handle_connect(self):
pass

def handle_close(self):
self.close()

def handle_read(self):
print 'READING.'
print self.recv(256)

def handle_write(self):
sent=self.send(self.url)
self.url=self.url[sent:]

t=T('aVerySlowSite','/')
asyncore.loop()
for i in range(0,10):
print '%d in main process' % i
time.sleep(1)

Suppose it's asynchronous, couple of '%d in main process' lines should
be mixed in the output of T.handle_read(), right? But I found that
actually main process was blocked at asyncore.loop(), until the the
socket was closed. My questions:
1, Did I do anything wrong?
2, Is it real asynchronous?
3, If not, where to get the real one(s)?

Any comment is welcome :)

-- 
http://mail.python.org/mailman/listinfo/python-list


pygobject replacement?

2007-11-14 Thread Linan
Hi,

I have a python library which is written years ago and heavily using
pygobject in binding signal/events (No GUI stuffs involve). Now I have
to use it in a totally different environment which doesnot allow to
install glib, gtk and gobject. Surely I don't want to change the whole
structure of handling signals/events. Is there any pure python
pygobject replacement that I can switch to, and change only functions
like emit?

Any suggestion is appreciated.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pygobject replacement?

2007-11-14 Thread Linan
Thanks. It's very helpful.

On Nov 14, 12:50 pm, Jarek Zgoda <[EMAIL PROTECTED]> wrote:
> Linan napisa³(a):
>
> > I have a python library which is written years ago and heavily using
> > pygobject in binding signal/events (No GUI stuffs involve). Now I have
> > to use it in a totally different environment which doesnot allow to
> > install glib, gtk and gobject. Surely I don't want to change the whole
> > structure of handling signals/events. Is there any pure python
> > pygobject replacement that I can switch to, and change only functions
> > like emit?
>
> I used to use Louie (http://pylouie.org/) and PyDispatcher. They are
> both synchronous, though, so to have real signal behaviour you have to
> use eg. threads.
>
> --
> Jarek Zgoda
> Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101
>
> "We read Knuth so you don't have to." (Tim Peters)


-- 
http://mail.python.org/mailman/listinfo/python-list