<s> import sys <EOL> import os <EOL> sys . path . insert ( <NUM_LIT:0> , os . path . abspath ( '<STR_LIT:..>' ) ) <EOL> import unittest <EOL> import time <EOL> import urllib <EOL> try : <EOL> from gevent . monkey import patch_socket <EOL> except ImportError : <EOL> print ( "<STR_LIT>" ) <EOL> else : <EOL> patch_socket ( ) <EOL> from async_gui . gevent_tasks import MultiGTask <EOL> from tests . test_engine import EngineTestCase , engine , async <EOL> class GeventExecutorTestCase ( EngineTestCase ) : <EOL> from async_gui . gevent_tasks import GTask as Task <EOL> from async_gui . gevent_tasks import MultiGTask as AllTasks <EOL> testing_gevent = True <EOL> def test_gevent_urllib ( self ) : <EOL> self . gevent_with_urllib ( ) <EOL> @ async <EOL> def gevent_with_urllib ( self ) : <EOL> def download ( url ) : <EOL> return urllib . urlopen ( url ) . read ( ) <EOL> delay = <NUM_LIT:1> <EOL> n = <NUM_LIT:5> <EOL> t = time . time ( ) <EOL> urls = [ "<STR_LIT>" % delay for _ in range ( n ) ] <EOL> result = yield MultiGTask ( [ self . Task ( download , url ) for url in urls ] ) <EOL> result2 = yield [ self . Task ( download , url ) for url in urls ] <EOL> elapsed = time . time ( ) - t <EOL> self . assertEqual ( len ( result ) , n ) <EOL> self . assertLess ( elapsed , delay * n ) <EOL> print ( elapsed ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
