Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/sqlalchemy/util/concurrency.py: 42%

40 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:35 +0000

1# util/concurrency.py 

2# Copyright (C) 2005-2023 the SQLAlchemy authors and contributors 

3# <see AUTHORS file> 

4# 

5# This module is part of SQLAlchemy and is released under 

6# the MIT License: https://www.opensource.org/licenses/mit-license.php 

7 

8from . import compat 

9 

10have_greenlet = False 

11greenlet_error = None 

12 

13if compat.py3k: 

14 try: 

15 import greenlet # noqa: F401 

16 except ImportError as e: 

17 greenlet_error = str(e) 

18 else: 

19 have_greenlet = True 

20 from ._concurrency_py3k import await_only 

21 from ._concurrency_py3k import await_fallback 

22 from ._concurrency_py3k import greenlet_spawn 

23 from ._concurrency_py3k import is_exit_exception 

24 from ._concurrency_py3k import AsyncAdaptedLock 

25 from ._concurrency_py3k import _util_async_run # noqa: F401 

26 from ._concurrency_py3k import ( 

27 _util_async_run_coroutine_function, 

28 ) # noqa: F401, E501 

29 from ._concurrency_py3k import asyncio # noqa: F401 

30 

31 # does not need greennlet, just Python 3 

32 from ._compat_py3k import asynccontextmanager # noqa: F401 

33 

34if not have_greenlet: 

35 

36 asyncio = None # noqa: F811 

37 

38 def _not_implemented(): 

39 # this conditional is to prevent pylance from considering 

40 # greenlet_spawn() etc as "no return" and dimming out code below it 

41 if have_greenlet: 

42 return None 

43 

44 if not compat.py3k: 

45 raise ValueError("Cannot use this function in py2.") 

46 else: 

47 raise ValueError( 

48 "the greenlet library is required to use this function." 

49 " %s" % greenlet_error 

50 if greenlet_error 

51 else "" 

52 ) 

53 

54 def is_exit_exception(e): # noqa: F811 

55 return not isinstance(e, Exception) 

56 

57 def await_only(thing): # noqa: F811 

58 _not_implemented() 

59 

60 def await_fallback(thing): # noqa: F811 

61 return thing 

62 

63 def greenlet_spawn(fn, *args, **kw): # noqa: F811 

64 _not_implemented() 

65 

66 def AsyncAdaptedLock(*args, **kw): # noqa: F811 

67 _not_implemented() 

68 

69 def _util_async_run(fn, *arg, **kw): # noqa: F811 

70 return fn(*arg, **kw) 

71 

72 def _util_async_run_coroutine_function(fn, *arg, **kw): # noqa: F811 

73 _not_implemented()