socket function that loops AND returns something
Bryan Olson
fakeaddress at nowhere.org
Thu Sep 16 04:46:18 EDT 2004
Brad Tilley wrote:
> [...] I want to get the data that the clients send out of
> the loop but at the same time keep the loop going so it can
> continue listening for connections. [...]
I'd classify the ways to do it somewhat differently than the
other responses:
-Start multiple lines of execution
- using threads
- using processes (which, in Python, is less portable)
-Wait for action on multiple sockets within a single thread
- using os.select
- using some less-portable asynchronous I/O facility
Those are the low-level choices. Higher level facilities, such
as Asyncore and Twisted, are themselves based on one or more of
those.
Different servers have different needs, but when in doubt use
threads. Threading on the popular operating systems has
improved vastly in the last several years. Running a thousand
simultaneous threads is perfectly reasonable. Programmers using
threads have to be aware of things like race conditions, but
when threads are handling separate connections, most of their
operations are independent of other threads.
--
--Bryan
More information about the Python-list
mailing list