File: asyncio_correct_patching.py

package info (click to toggle)
python-eventlet 0.40.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 3,200 kB
  • sloc: python: 25,101; sh: 78; makefile: 31
file content (32 lines) | stat: -rw-r--r-- 851 bytes parent folder | download | duplicates (5)
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
28
29
30
31
32
"""
asyncio submodules continue to have the original, real socket module even after
monkeypatching.
"""

import sys


def assert_correct_patching():
    from eventlet.greenio.base import GreenSocket
    import asyncio.selector_events
    if asyncio.selector_events.socket.socket is GreenSocket:
        raise RuntimeError("Wrong socket class, should've been normal socket.socket")

    import asyncio.selector_events
    if asyncio.selector_events.selectors is not sys.modules["__original_module_selectors"]:
        raise RuntimeError("Wrong selectors")

    if asyncio.selector_events.selectors.select is not sys.modules["__original_module_select"]:
        raise RuntimeError("Wrong select")


import eventlet.hubs
eventlet.hubs.get_hub()
assert_correct_patching()

import eventlet
eventlet.monkey_patch()
assert_correct_patching()


print("pass")