Josiah Carlson <[EMAIL PROTECTED]> added the comment:

My suggestion: don't do that.  Asynchronous sockets, and
asyncore/related libraries are not designed for, nor intended to be used
as part of a threaded IO application.  Why?  Because most protocols are
very concerned with data ordering, and sending from multiple threads can
cause *serious* issues.  I do not believe that this should change.

Note that you can work around this limitation by using something like
the following, but again, this is not suggested (you should instead work
asyncore.poll() calls into some sort of main loop within your application).

from Queue import Queue

check_threads = 0

class my_async(asyncore.dispatcher):
    def __init__(self, *args, **kwargs):
        self.q = Queue()
        asyncore.dispatcher.__init__(self, *args, **kwargs)
    def push_t(self, data):
        global check_threads
        self.q.put(data)
        check_threads = 1
    def handle_threaded_push(self):
        while not self.q.empty():
            self.push(self.q.get())

def loop(timeout=.1, map=None):
    global check_threads
    if map is None:
        map = asyncore.socket_map
    while 1:
        asyncore.poll(timeout, map)
        if check_threads:
            check_threads = 0
            for v in map.values():
                try:
                    v.handle_threaded_push()
                except:
                    #handle exceptions better here
                    pass

----------
assignee:  -> josiahcarlson
resolution:  -> wont fix
status: open -> pending

__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue2808>
__________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to