我正在使用 C++17 并行标准库算法和std::execution::par执行策略。我在一台 4 核笔记本电脑上使用 Ubuntu,使用 clang 11 编译器和 VS Code 的 cmake 扩展进行构建(尽管我也检查了简单的单命令行编译而不使用 cmake)。
根据以下观察,该程序似乎仅使用 1 个线程:
std::execution::seq(常规、顺序算法)top -H,我只看到 1 个线程,CPU 使用率约为 100%sort使用 Ubuntu 的系统监视器,我看到一个核心在执行过程中处于活动状态(但如果我重复使用 for 循环,则活动核心可能会在不同调用之间发生变化)。代码示例:
#include <vector>
#include <iostream>
#include <algorithm>
#include <execution>
#include <chrono>
#include <thread>
int main()
{
const int N = 10000000;
std::vector<int> vec(N);
std::chrono::duration<double> elapsed;
unsigned int nThreads = std::thread::hardware_concurrency();
std::cout << "number of available threads: " << nThreads << "\n"; // this …Run Code Online (Sandbox Code Playgroud) tl; dr - 在使用SQLAlchemy将密码插入MySQL DB之前,如何使用PassLib等Python端库来密码密码?
好吧,所以我一直在我的桌子上敲我的头一两天试图解决这个问题,所以在这里:
我正在使用Pyramid/SQLAlchemy编写Web应用程序,我正在尝试与MySQL数据库的Users表接口.
最终,我想做以下事情:
将密码与哈希值进行比较:
if user1.password == 'supersecret'
Run Code Online (Sandbox Code Playgroud)
插入新密码:
user2.password = 'supersecret'
Run Code Online (Sandbox Code Playgroud)
我希望能够在进入数据库之前使用PassLib来对我的密码进行哈希处理,而且我不是真的喜欢使用内置的MySQL SHA2功能,因为它没有被腌制.
但是,只是为了尝试它,我确实使用SQL端函数:
from sqlalchemy import func, TypeDecorator, type_coerce
from sqlalchemy.dialects.mysql import CHAR, VARCHAR, INTEGER
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column
class SHA2Password(TypeDecorator):
"""Applies the SHA2 function to incoming passwords."""
impl = CHAR(64)
def bind_expression(self, bindvalue):
return func.sha2(bindvalue, 256)
class comparator_factory(CHAR.comparator_factory):
def __eq__(self, other):
local_pw = type_coerce(self.expr, CHAR)
return local_pw == func.sha2(other, 256)
class User(Base):
__tablename__ = 'Users'
_id = Column('userID', …Run Code Online (Sandbox Code Playgroud)