问题描述
$user = '';
$pass = '';
$db = '';
$port = '13306';
$host = 'instance.sftp.wpengine.com'; //put your account name instead of 'instance' here
$options = ['default-auth'=>'MysqL_native_password',PDO::MysqL_ATTR_SSL_CA=>__DIR__.'/wpengine_root_ca.pem',PDO::MysqL_ATTR_SSL_VERIFY_SERVER_CERT => false];
$dbh = new PDO('MysqL:host='.$host.';port='.$port.';dbname='.$db.';default-auth=MysqL_native_password',$user,$pass,$options);
这里卡住了。
>>> import concurrent.futures
>>> from collections import namedtuple
>>> #1. Initialise namedtuple here
>>> # tm = namedtuple("tm",["pk"])
>>> class T:
... #2. Initialise named tuple here
... #tm = namedtuple("tm",["pk"])
... def __init__(self):
... #3: Initialise named tuple here
... tm = namedtuple("tm",["pk"])
... self.x = {'key': [tm('value')]}
... def test1(self):
... with concurrent.futures.ProcesspoolExecutor(max_workers=1) as executor:
... results = executor.map(self.test,["key"])
... return results
... def test(self,s):
... print(self.x[s])
...
>>> t = T().test1()
如果我在类外部(在#1中)初始化命名的元组,则可以正常工作。有人可以让我知道如果我按照#2或#3进行初始化是什么问题吗?
解决方法
您没有更改初始化namedtuple的位置。您正在更改创建命名元组 class 的位置。
使用collections.namedtuple
在模块“ y”中创建名为“ x”的namedtuple类时,其__module__
设置为'y'
,其__qualname__
设置为{ {1}}。酸洗和解酸依赖于此类实际上在这些属性指示的'x'
位置中可用的此类,但是在您的示例的情况2和3中,不是。
Python无法腌制namedtuple,这会中断与工作人员的进程间通信。在工作进程中执行y.x
依赖于在工作进程中腌制self.test
并取消其副本的拷贝,如果self.test
是可以的类的实例,则不会发生这种情况。不能腌。