This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author r.david.murray
Recipients kevinburke, r.david.murray
Date 2014-11-17.18:54:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1416250449.98.0.457564433482.issue22889@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-11-17 18:54:10r.david.murraysetrecipients: + r.david.murray, kevinburke
2014-11-17 18:54:09r.david.murraysetmessageid: <1416250449.98.0.457564433482.issue22889@psf.upfronthosting.co.za>
2014-11-17 18:54:09r.david.murraylinkissue22889 messages
2014-11-17 18:54:09r.david.murraycreate