R. David Murray added the comment:

Oh, my apologies.  I totally missed your link to the go example when I first 
read your message.

Yes, Python supports the equivalent.  In the asyncio module, which is our 
closest equivalent to goroutines, the functionality exists implicitly: the base 
event loop has a getaddrinfo coroutine that is used for DNS lookup, and it is 
run in a separate thread to keep from blocking the event loop.  If you time out 
(wait_for with a timeout) a coroutine that ends up doing a DNS request, your 
wait_for call will time out whether or not the getaddrinfo DNS lookup has timed 
out.

Using asyncio isn't quite as simple as prefixing a function name with 'go', but 
it isn't all that hard, either.  Nevertheless, if you aren't using asyncio for 
the rest of your program, it probably makes more sense to write a function that 
launches a thread to do the getaddrinfo and does a wait on the thread with a 
timeout.  (But you might want to check out if asyncio applies to your overall 
problem.)

So yes, Python can do this, but I don't think it makes sense to build it in to 
the stdlib's socket module (say), since unlike go async and threading aren't 
part of the core language but are instead libraries themselves.  asyncio 
already has it built in.  For the thread based version, putting a recipe on one 
of the recipe sites might be good, if there isn't one already.

----------
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue22889>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to