diff options
author | Denis Bilenko <denis@ag-projects.com> | 2008-10-08 19:20:10 +0700 |
---|---|---|
committer | Denis Bilenko <denis@ag-projects.com> | 2008-10-08 19:20:10 +0700 |
commit | b28fb130c80eda36a455ad341d1575c33d48ce6d (patch) | |
tree | dff4d73ad10c2d8113c46cd808b2820934a1b6e0 /examples | |
parent | c0a7b7cd3e31c372d96a2cce8b5359122f21db4b (diff) | |
download | eventlet-b28fb130c80eda36a455ad341d1575c33d48ce6d.tar.gz |
simple example on socket,spawn
Diffstat (limited to 'examples')
-rw-r--r-- | examples/connect.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/examples/connect.py b/examples/connect.py new file mode 100644 index 0000000..1a52f60 --- /dev/null +++ b/examples/connect.py @@ -0,0 +1,23 @@ +import sys +from eventlet.green import socket +from eventlet.green import time +from eventlet.api import spawn + +def client(): + # using domain name directly is of course possible too + # this is a test to see that dns lookups happen simultaneously too + ip = socket.gethostbyname('www.google.com') + c = socket.socket() + c.connect((ip, 80)) + c.send('GET /\r\n\r\n') + print c.recv(1024) + + +for x in range(5): + # note that spawn doesn't switch to new greenlet immediately. + spawn(client) + +# the execution ends with the main greenlet exit (by design), so we need to give control +# to other greenlets for some time here. +time.sleep(1) +sys.stdout.flush() |