File: test_close_backend_fd.py

package info (click to toggle)
python-gevent 1.0.1-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 9,948 kB
  • ctags: 12,954
  • sloc: python: 39,061; ansic: 26,289; sh: 13,582; makefile: 833; awk: 18
file content (27 lines) | stat: -rw-r--r-- 934 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
import gevent
from gevent import core


for count in xrange(2):
    for backend in core.supported_backends():
        hub = gevent.get_hub(backend, default=False)
        assert hub.loop.backend == backend, (hub.loop.backend, backend)
        gevent.sleep(0.001)
        fileno = hub.loop.fileno()
        if fileno is not None:
            print '%s. Testing %r: %r' % (count, backend, hub)
            os.close(fileno)
            try:
                gevent.sleep(0.001)
            except SystemError, ex:
                if '(libev)' in str(ex):
                    print 'The error is expected: %s' % ex
                else:
                    raise
            else:
                raise AssertionError('gevent.sleep() is expected to fail after loop fd was closed')
        else:
            print '%s. %r lacks fileno()' % (count, backend)
        hub.destroy()
        assert 'destroyed' in repr(hub), repr(hub)