set svn:keywords property for proper keywords expansion
[plcapi.git] / pycurl / tests / test_multi6.py
1 #! /usr/bin/env python
2 # -*- coding: iso-8859-1 -*-
3 # vi:ts=4:et
4 # $Id$
5
6 import sys, select, time
7 import pycurl
8
9 c1 = pycurl.Curl()
10 c2 = pycurl.Curl()
11 c3 = pycurl.Curl()
12 c1.setopt(c1.URL, "http://www.python.org")
13 c2.setopt(c2.URL, "http://curl.haxx.se")
14 c3.setopt(c3.URL, "http://slashdot.org")
15 c1.body = open("doc1", "wb")
16 c2.body = open("doc2", "wb")
17 c3.body = open("doc3", "wb")
18 c1.setopt(c1.WRITEFUNCTION, c1.body.write)
19 c2.setopt(c2.WRITEFUNCTION, c2.body.write)
20 c3.setopt(c3.WRITEFUNCTION, c3.body.write)
21
22 m = pycurl.CurlMulti()
23 m.add_handle(c1)
24 m.add_handle(c2)
25 m.add_handle(c3)
26
27 # Number of seconds to wait for a timeout to happen
28 SELECT_TIMEOUT = 10
29
30 # Stir the state machine into action
31 while 1:
32     ret, num_handles = m.perform()
33     if ret != pycurl.E_CALL_MULTI_PERFORM:
34         break
35
36 # Keep going until all the connections have terminated
37 while num_handles:
38     # The select method uses fdset internally to determine which file descriptors
39     # to check.
40     m.select(SELECT_TIMEOUT)
41     while 1:
42         ret, num_handles = m.perform()
43         # Print the message, if any
44         print m.info_read(1)
45         if ret != pycurl.E_CALL_MULTI_PERFORM:
46             break
47
48 # Cleanup
49 m.remove_handle(c3)
50 m.remove_handle(c2)
51 m.remove_handle(c1)
52 m.close()
53 c1.body.close()
54 c2.body.close()
55 c3.body.close()
56 c1.close()
57 c2.close()
58 c3.close()
59 print "http://www.python.org is in file doc1"
60 print "http://curl.haxx.se is in file doc2"
61 print "http://slashdot.org is in file doc3"
62