小编Chr*_*unt的帖子

在本地检查bitbucket pull请求

我找到了这个要点:https: //gist.github.com/kennethreitz/3709868

我正在使用bitbucket,我正在寻找类似的功能.

你能帮助我吗?谢谢

bitbucket

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

Docker Quickstart Terminal无法在Windows 10中启动VirtualBox VM

我已经多次尝试通过Docker Quickstart Terminal启动Docker VM.default在VirtualBox中删除虚拟机后,我收到以下输出

Creating Machine default...
Running pre-create checks...
Creating machine...
(default) OUT | Creating VirtualBox VM...
(default) OUT | Creating SSH key...
(default) OUT | Starting VirtualBox VM...
Error creating machine: Error in driver during machine creation: exit status 1
Looks like something went wrong... Press any key to continue...
Run Code Online (Sandbox Code Playgroud)

为了进一步排除故障,我尝试default使用Start> Headless Start直接在VirtualBox GUI中启动计算机,如其他Docker问题所示.启动失败,我收到一个错误对话框,其中包含以下内容:

Failed to open/create the internal network 'HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter' (VERR_INTNET_FLT_IF_NOT_FOUND).

Failed to attach the network LUN (VERR_INTNET_FLT_IF_NOT_FOUND).

Result Code: …
Run Code Online (Sandbox Code Playgroud)

windows virtualbox docker docker-toolbox

11
推荐指数
1
解决办法
8942
查看次数

在Ruby on Rails中使用由外部API支持的模型的ActiveRecord接口

我正在尝试在我的Rails应用程序中使用模型从外部API检索信息.我想要做的是以类似于ActiveRecord模型提供的方式访问我的数据模型(可能包含多个API调用产生的信息)(特别是关联,以及相同类型的可链式查询方法).

我最初的本能是重新创建我想要的ActiveRecord部分并合并这个API.不想"重新发明轮子"并确切地看到增加更多功能需要多少工作让我退后一步并重新评估如何处理这个问题.

我已经找到了在没有表的情况下使用ActiveRecord的方法(参见:Railscast#193 Tableless Model和这里的博客文章)并查看了ActiveRecord.因为ActiveModel似乎只包含Validations,所以我不确定在这种情况下它是非常有用的.在没有表格的情况下使用ActiveRecord的解决方法似乎是最好的选择,但我怀疑有一种更清洁的方式,我只是没有看到.

是一个要点,其中包含我尝试重新创建ActiveRecord功能时编写的一些代码,这些代码是从ActiveRecord源本身大量借用的.

我的问题归结为:我可以通过实现上面指定的ActiveRecord的变通方法或者自己重新创建功能来获得我想要的功能(链接查询方法,关系),但这些是非常理想的解决方案吗?

ruby api ruby-on-rails

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

如何从 boost::asio::post 获得未来?

我正在使用 Boost 1.66.0,其中 asio 内置支持与期货互操作(现在已经有一段时间了)。我在网上看到的例子说明如何使用网络功能,例如,当达到这个干净async_readasync_read_some等等。这是通过提供完成boost::asio::use_future到位完成处理,这会导致启动函数返回的future预期。

我需要提供什么类型的对象或将我的函数包装在其中以获得相同的行为boost::asio::post

我发布工作的目的是在一个链的上下文中执行它,否则等待工作完成,所以我可以获得我想要做的行为:

std::packaged_task<void()>  task( [] { std::cout << "Hello world\n"; } );
auto  f = task.get_future();
boost::asio::post(
    boost::asio::bind_executor(
        strand_, std::move( task ) ) );
f.wait();
Run Code Online (Sandbox Code Playgroud)

但是根据boost::asio文档,返回类型boost::asio::post以相同的方式作为用于功能推导喜欢boost::asio::async_read,所以感觉必须有一个更好的方式,可避免中间packaged_task。不像async_read没有“其他工作”可以完成,post所以提供boost::asio::use_future没有意义,但我们可以定义一个async_result特征来获得相同的发布行为。

是否有包装器或具有定义必要特征的东西以获得我想要的行为,还是我需要自己定义它?

c++ boost future boost-asio

7
推荐指数
2
解决办法
3567
查看次数

asyncio.run_in_executor是否含糊不清?

我有一个服务器应用程序,当客户要求我安排一些工作,如

def work():
    time.sleep(5)

fut = asyncio.get_event_loop().run_in_executor(None, work)
Run Code Online (Sandbox Code Playgroud)

await fut后来明确要求它.我的用例要求立即run_in_executor提交work函数,并且在我的环境中表现如预期(Ubuntu 16.04,Python 3.7.1).

由于我的应用程序依赖于这种行为,我想验证它不是可能改变的东西,所以我检查了几个资源:

  1. 文件似乎有点含糊.awaitable好像它可以适用于方法或返回值-尽管文本的身体不说,它返回一个asyncio.Future明确的.
  2. 指定asyncio的PEP 3156 - 在这里它没有说明run_in_executor是一个协程.
  3. 在一些问题中,是否run_in_executor返回等待或协程本身的函数似乎被视为实现细节.见2567532327.
  4. AbstractEventLoop.run_in_executor被指定为协程,但是实现BaseEventLoop.run_in_executor是一个普通的函数.

1和2似乎主要表明当前的行为是正确的,但3和4是有关的.这似乎是界面的一个非常重要的部分,因为如果函数本身是一个协程,那么它将不会开始执行(因此不会安排工作),直到等待它为止.

依赖当前的行为是否安全?如果是这样,将接口更改AbstractEventLoop.run_in_executor为普通函数而不是协程是否合理?

python python-asyncio

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

如何告诉 Python 脚本停止调试器附加到进程?

有没有办法告诉 Python 在脚本中的某个点停止执行并等待调试器附加到进程?

有没有类似于Debugger.Break()Python 中的dot-Net 的东西?

python debugging

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

Clang 为已使用的类型别名发出“未使用的类型别名”警告

我有一些 Clang 正在为其生成警告的代码。这是从实际代码中简化的,但精神是一样的。this_t在本地类中用于实例化其他一些模板类。

template<class T>
struct value_holder
{
    T  value;
};

template<class T>
int get_value()
{
    struct value_t
    {
        using this_t = value_t;
        //    ^ here
        static value_holder<this_t> val()
        {
            return value_holder<this_t>();
        }

        operator int()
        { return 0; }
    };
    return value_t::val().value;
}

int main(int argc, char** argv) {
    return get_value<void>();
}
Run Code Online (Sandbox Code Playgroud)

使用 编译时-std=c++1z -Wall,Clang 会警告unused type alias

main.cpp:14:15: warning: unused type alias 'this_t' [-Wunused-local-typedef]
        using this_t = value_t;
              ^
1 warning generated.
Run Code Online (Sandbox Code Playgroud)

您可以在 …

c++ clang llvm-clang type-alias clang++

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

无法将 awaitable 传递给 asyncio.run_coroutine_threadsafe

我观察到该asyncio.run_coroutine_threadsafe函数不接受一般的可等待对象,我不明白这种限制的原因。观察

import asyncio


async def native_coro():
    return


@asyncio.coroutine
def generator_based_coro():
    return


class Awaitable:
    def __await__(self):
        return asyncio.Future()


loop = asyncio.get_event_loop()

asyncio.run_coroutine_threadsafe(native_coro(), loop)
asyncio.run_coroutine_threadsafe(generator_based_coro(), loop)
asyncio.run_coroutine_threadsafe(Awaitable(), loop)
Run Code Online (Sandbox Code Playgroud)

使用 Python 3.6.6 运行它会产生

Traceback (most recent call last):
  File "awaitable.py", line 24, in <module>
    asyncio.run_coroutine_threadsafe(Awaitable(), loop)
  File "~/.local/python3.6/lib/python3.6/asyncio/tasks.py", line 714, in run_coroutine_threadsafe
    raise TypeError('A coroutine object is required')
TypeError: A coroutine object is required
Run Code Online (Sandbox Code Playgroud)

第 24 行在哪里asyncio.run_coroutine_threadsafe(Awaitable(), loop)

我知道我可以将我的可等待对象包装在一个定义如下的协程中

awaitable = Awaitable()

async def wrapper():
    return await awaitable

asyncio.run_coroutine_threadsafe(wrapper(), …
Run Code Online (Sandbox Code Playgroud)

python python-asyncio

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