小编Gre*_*uhn的帖子

手臂睡眠模式进入和退出差异WFE,WFI

我是ARM架构的新手,我正试图围绕唤醒机制.

首先,我发现很难找到关于此的好消息.ARM的文档似乎非常简洁.

我想要了解的是,当Cortex(尤其是我正在使用的M0)将被唤醒时.

作为参考,我还咨询了以下内容:

WFE指令的文档是:

    3.7.11. WFE
    Wait For Event.
    Syntax
    WFE
    Operation
    If the event register is 0, WFE suspends execution until 
      one of the following events occurs:
    an exception, unless masked by the exception mask registers or the current
      priority level
    an exception enters the Pending state, if SEVONPEND in the 
      System Control Register is set
    a Debug Entry request, if debug is enabled
    an event signaled by a peripheral or another processor in a 
      multiprocessor …
Run Code Online (Sandbox Code Playgroud)

arm interrupt cortex-m

9
推荐指数
1
解决办法
1万
查看次数

管道python将stdout流输出记录到grep

不久前我知道这样做的原因,但后来我忘记了,谷歌搜索了 5 分钟还没有找到答案。

我写了一个 python 脚本,它有两个处理程序。一种用于文件,一种用于流。

一切都如我所愿。

现在,我想快速搜索输出中正在打印到终端的内容,但是通过 grep 管道脚本的输出似乎不起作用,因为所有输出仍然会打印到终端。

我正在使用 unix 和 python 2.7

这可能是一个重复的问题,但我找不到答案。

这是我对日志记录模块的设置:

def setup_logger(verbosity):
    #logger = logging.getLogger(regress.app_name)
    logger = logging.getLogger('components')
    logger.setLevel(logging.DEBUG)
    # create file handler which logs even debug messages
    fh = logging.FileHandler(Config.logging_file_name, mode='w')
    fh.setLevel(logging.DEBUG)
    # create console handler with a higher log level
    ch = logging.StreamHandler()
    ch.setLevel({True:logging.DEBUG, False:logging.INFO}[verbosity])
    # create formatter and add it to the handlers
    file_formatter = logging.Formatter('%(asctime)s - %(pathname)s - %(funcName)s - %(name)s - %(levelname)s - %(lineno)s - %(message)s')

    console_formatter = …
Run Code Online (Sandbox Code Playgroud)

python linux stdout pipe

7
推荐指数
1
解决办法
3268
查看次数

可以换行到下一行的 restructuredText 内联文字(用于 PDF 输出)

我正在使用 restructuredText 创建一个包含 tom 日志文件输出的报告。

我所拥有的是一些带有编号的文字列表的部分。这看起来像这样:

#. ``some log file output``
#. ``more output``
Run Code Online (Sandbox Code Playgroud)

现在的问题是,当我使用 rst2pdf 将其转换为 PDF 时,文字有时会很长并且从页面上流下来。

我想要的是将一段文本标记为可以像普通文本一样流到下一行的代码文字。

我想要这个,因为如果我不将日志文件输出标记为文字,则日志文件输出中有时会出现一些 rust 将其解释为内联标记或其他与 rst 相关的命令。

关于如何最好地做到这一点的任何其他建议?

我知道我可以确保源 rst 文件只有特定宽度的行,但这会使源文件看起来很糟糕并且难以编辑。

我尝试了以下两件事,但都无济于事:

我找到了一个 rst2pdf 选项:

--fit-literal-mode=MODE
                What to do when a literal is too wide.
                One of error,overflow,shrink,truncate. 
                Default="shrink"
Run Code Online (Sandbox Code Playgroud)

经过一番研究,我发现提到了文字的包装选项。我让 rst2pdf 使用以下方法转储默认样式表:

rst2pdf --print-stylesheet然后我保存并修改了它,以便将wordWrap下面的选项literal更改为CJK.

restructuredtext literals rst2pdf

5
推荐指数
0
解决办法
852
查看次数

python 散景调色板图例

我正在尝试 Python 的很棒的Bokeh可视化库。我对此有一个问题。我正在使用此示例作为参考来制作等高线图之类的东西。

它工作得很好,但为了完成这个,我希望将颜色图作为图例。基本上我希望图表的读者能够理解颜色的含义。有办法做到这一点吗?

python legend color-mapping bokeh

5
推荐指数
1
解决办法
2862
查看次数

python日志关闭和应用程序退出

我在应用程序中使用日志记录模块,我突然想到,如果日志记录模块支持一种可以正常关闭文件句柄等然后关闭应用程序的方法,那就太好了。

例如:

logger = logging.getLogger('my_app')
logger.fatal("We're toast!")
Run Code Online (Sandbox Code Playgroud)

致命的方法(或类似的方法)将:

  1. 正常记录消息
  2. logging.shutdown()
  3. 调用 sys.exit(1)

想法?这样的东西存在吗?这是一个坏主意吗?

我为什么要这个?好吧,我的代码中有几个地方我希望应用程序死掉,并且不断重复代码来执行23似乎是一种浪费。

python logging

5
推荐指数
1
解决办法
6560
查看次数

python RPyC 用户数

我希望使用 RPyC 为硬件板提供 API 作为服务。该板一次只能满足一个用户的需求。有什么办法可以让 RPyC 强制执行一次只有一个用户可以访问吗?

python rpyc

5
推荐指数
1
解决办法
163
查看次数

Python Enum类成员资格

当以编程方式使用Python 3中引入的Enum类时,程序员应如何检查给定整数的Enum成员资格?

显然,你可以请求宽恕,但是否有会员检查功能,否则我错过了?更明确地说,我想取一个整数值并检查它的值是否对应于有效的枚举.

from enum import Enum

class TestEnum(Enum):
    a = 0
    b = 1
    c = 2
Run Code Online (Sandbox Code Playgroud)

输出:

In [13]: TestEnum(0)
Out[13]: <TestEnum.a: 0>

In [14]: TestEnum(4)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-14-09c663e9e214> in <module>()
----> 1 TestEnum(4)

C:\Anaconda3\lib\enum.py in __call__(cls, value, names, module, qualname, type, start)
    239         """
    240         if names is None:  # simple value lookup
--> 241             return cls.__new__(cls, value)
    242         # otherwise, functional API: we're …
Run Code Online (Sandbox Code Playgroud)

python enums

5
推荐指数
1
解决办法
1429
查看次数

gitlab-ci 作业未运行脚本

我是 gitlab-ci 的新手,正在尝试基于 gitlab 模板的最小 Python 应用程序。

我的 .gitlab-ci.yml 文件如下:

# This file is a template, and might need editing before it works on your project.
# Official language image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/python/tags/
#image: python:latest

# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache"

stages:
  - test
  - run

# Pip's cache doesn't store the python packages
# https://pip.pypa.io/en/stable/reference/pip_install/#caching
#
# …
Run Code Online (Sandbox Code Playgroud)

gitlab-ci

5
推荐指数
1
解决办法
3533
查看次数

Pytest assert_has_calls用法

我正在尝试使用pytest的模拟程序夹具,特别是模拟模块中的assert_has_calls函数。

当我运行这个:

import os
from mock import call
def test_assert_(mocker):
    mocker.patch('os.remove')

    file_list = [f'file_{i}.txt' for i in range(20)]

    for f in file_list:
        os.remove(f)

    calls = [call(f) for f in file_list]

    assert os.remove.assert_has_calls(calls, any_order=True)
Run Code Online (Sandbox Code Playgroud)

我得到这个:

c:\temp
? python -m pytest test_mock.py
============================= test session starts =============================
platform win32 -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
rootdir: c:\temp, inifile:
plugins: mock-1.6.3
collected 1 items

test_mock.py F

================================== FAILURES ===================================
________________________________ test_assert_ _________________________________

mocker = <pytest_mock.MockFixture object at 0x0000000003ED6BE0>

    def test_assert_(mocker):
        mocker.patch('os.remove') …
Run Code Online (Sandbox Code Playgroud)

pytest python-3.x

3
推荐指数
1
解决办法
1488
查看次数

pytest 测试参数化覆盖

我目前正在参数化我使用的所有测试用例pytest_generate_tests,这很有效。

我现在想做的是为特定测试覆盖此行为。如果我尝试pytest.mark.parametrize在测试本身上使用装饰器,我会收到一个ValueError: duplicate错误,这是可以理解的,因为我现在试图在两个地方对测试进行参数化。

有没有办法可以覆盖这个测试用例的“默认”参数化?

我可以通过执行以下操作来实现这一点,但这是一种非常hacky的方法:

def pytest_generate_tests(metafunc):
    fixture_modes = ['mode1', 'mode2']
    if 'fixture' in metafunc.fixturenames:
        fixture  = metafunc.config.getoption('fixture')
        if fixture:
            fixture_modes = [fixture]
        if metafunc.function.__name__ != 'func_to_skip':
            metafunc.parametrize('fixture_mode', fixture_modes, indirect=True)
Run Code Online (Sandbox Code Playgroud)

有一个更好的方法吗?

python testing pytest

3
推荐指数
1
解决办法
569
查看次数