zoukankan      html  css  js  c++  java
  • ubuntu 18.04 run python3.7

    install

    sudo apt install python3.7 python3-venv python3.7-venv
    python3.7 -m venv py37-venv
    . py37-venv/bin/activate
    sudo apt install build-essential libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev tk-dev libffi-dev
    
    # run your commend
    #  ...
    
    deactivate # exit

    In your project

    . py37-venv/bin/activate
    # cd your project path
    # sudo apt install build-essential libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev tk-dev libffi-dev
     
    pip3.7 install  wheel
    pip3.7 install -r  requirements.txt
    pip3.7 install -r test-requirements.txt
     
    # run your testcase
    python -m unittest run cyborg.tests.unit.objects.test_extarq.TestExtARQObject
    
    deactivate # exit
    

    Example:  

    cat testcase.py

     1 from functools import wraps
     2 from concurrent.futures import  ThreadPoolExecutor
     3 import six
     4 import time
     5 import traceback
     6 
     7 
     8 from oslotest import base
     9 
    10 
    11 def wrap_job_tb(msg="Reason: %s"):
    12     """Wrap a function with a is_job tag added, and catch Excetpion."""
    13     def _wrap_job_tb(method):
    14         @wraps(method)
    15         def _impl(self, *args, **kwargs):
    16             try:
    17                 output = method(self, *args, **kwargs)
    18             except Exception as e:
    19                 print(msg, six.text_type(e))
    20                 print(traceback.format_exc())
    21                 raise Exception("just a test error")
    22             return output
    23         setattr(_impl, "is_job", True)
    24         return _impl
    25     return _wrap_job_tb
    26 
    27 
    28 @wrap_job_tb("Error during job.")
    29 def job1(t1=0):
    30     print(time.time())
    31     print("sleep %s second" % t1)
    32     time.sleep(t1)
    33     print(time.time())
    34     return "Hello, world"
    35     raise Exception("Error")
    36 
    37 
    38 def spawn(func, *args, **kwargs):
    39     """Passthrough method for ThreadPoolExecutor.
    40 
    41     It will also grab the context from the threadlocal store and add it to
    42     the store on the new thread.  This allows for continuity in logging the
    43     context when using this method to spawn a new thread.
    44     """
    45     # Ref: https://pythonhosted.org/futures/
    46     max_workers = kwargs.pop("workers", 2)
    47     executor = ThreadPoolExecutor(max_workers=max_workers)
    48     future = executor.submit(func, *args, **kwargs)
    49     return executor, future
    50 
    51 
    52 class TestCase(base.BaseTestCase):
    53     def setUp(self):
    54         super(TestCase, self).setUp()
    55 
    56     def test_foo(self):
    57         print("Test foo")
    58 
    59     def test_bar(self):
    60         print("Test bar")
    61 
    62     def test_job(self):
    63         ex, f = spawn(job1, 1)
    64         ex.shutdown(wait=False)
    65         f.result()
    View Code

    run the example:

    . py37-venv/bin/activate
    # cd your project path
      
    pip3.7 install  wheel
    pip3.7 install  six oslotest 
    
    python -m unittest run testcase
    
    deactivate # exit
    

    This setting is used for the conflict between eventlet and ThreadPoolExecutor

    Modules with known eventlet monkey patching issues were imported prior to eventlet monkey patching: urllib3, oslo_context.c$
    ntext. This warning can usually be ignored if the caller is only importing and not executing nova code.
    

      

  • 相关阅读:
    nginx通过配置防止DDoS攻击
    BZOJ 2120 数颜色(单点修改莫队)
    数论模板
    BZOJ 2002 [Hnoi2010]Bounce 弹飞绵羊(分块)
    HDU 4609 3-idiots(FFT)
    BZOJ 3527 [Zjoi2014]力(FFT)
    快速对拍
    HDU 1402 A * B Problem Plus(FFT)
    FFT
    BZOJ 5319: [Jsoi2018]军训列队(可持久化线段树)
  • 原文地址:https://www.cnblogs.com/shaohef/p/12307235.html
Copyright © 2011-2022 走看看