예제 #1
0
파일: gevent_example.py 프로젝트: tmc/eio
def do_io(n_megs, use_eio=False):

    r = os.open("/dev/urandom", os.O_RDONLY)

    print "\nreading %s megs from /dev/urandom" % n_megs

    if use_eio:
        eio.init(want_poll, done_poll)

        r_event = Event()

        def set_r_event(result):
            r_event.set()

        buf = eio.read(r, 1024 * 1024 * n_megs, 0, set_r_event)

        print "waiting"
        r_event.wait()
    else:
        buf = os.read(r, 1024 * 1024 * n_megs)
    print "\ndone."

    gevent.sleep(0.5)
예제 #2
0
파일: test.py 프로젝트: tmc/eio
import unittest

def print_stats():
    print '\tstats:'
    print '\t\tnum reqs:\t', eio.nreqs()
    print '\t\tnum ready:\t', eio.nready()
    print '\t\tnum pending:\t', eio.npending()
    print '\t\tnum threads:\t', eio.nthreads()
    
def want_callback():
    print 'Want Called!'

def done_callback():
    print 'Done Called!'

print eio.init(want_callback, done_callback)

class TestDirectoryOperations(unittest.TestCase):
    
    def setUp(self):
        print 'setup'
        print_stats()

    def tearDown(self):
        print 'setup'
        print_stats()

    def test_mkdir(self):
        def mkdir_cb(foo):
            print 'mkdir callback', foo
        
예제 #3
0
파일: demo_port.py 프로젝트: tmc/eio

#int
#main (void)
if __name__ == '__main__':
#{
#  printf ("pipe ()\n");
    print 'pipe ()'
#  if (pipe (respipe)) abort ();
    respipe = os.pipe()
#
#  printf ("eio_init ()\n");
    print 'eio_init ()'

#  if (eio_init (want_poll, done_poll)) abort ();
    if eio.init(want_poll, done_poll):
#    if eio.init():
        print 'init failed, aborting'
        os.abort()
#
#  do
#    {
#      /* avoid relative paths yourself(!) */
#      eio_mkdir ("eio-test-dir", 0777, 0, res_cb, "mkdir");
    r = eio.mkdir('eio-test-dir', 0777)
#      eio_nop (0, res_cb, "nop");
    eio.nop()
#      eio_stat ("eio-test-dir", 0, stat_cb, "stat");
    eio.stat('eio-test-dir', stat_callback)
#      eio_lstat ("eio-test-dir", 0, stat_cb, "stat");
    eio.lstat('eio-test-dir')