小编Ada*_*dam的帖子

python apply_async不调用方法

我有一种需要处理大型数据库的方法,需要花费数小时/天的时间来挖掘参数存储在一个(长)列表中,其中应在一批中处理 max X 。该方法不需要返回任何内容,但我返回“True”表示“有趣”......

当我线性迭代它时(生成/附加此处未看到的其他表中的结果),该函数工作正常,但我无法获得 apply_async 或 map_async 工作。(它之前在其他项目中有效)任何关于我可能做错了什么的提示将不胜感激,提前致谢!参见下面的代码:

    import multiprocessing as mp

    class mainClass:
        #loads of stuff

    def main():
        multiprocess = True
        batchSize = 35

        mC = mainClass()
        while True:
            toCheck = [key for key, value in mC.lCheckSet.items()] #the tasks are stored in a dictionary, I'm referring to them with their keys, which I turn to a list here for iteration.
            if multiprocess == False:
                #this version works perfectly fine
                for i in toCheck[:batchSize]:
                    mC.check(i)
            else:
                #the async version …
Run Code Online (Sandbox Code Playgroud)

multiprocessing python-3.x

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

python-3.x 酸洗创建空文件

我是 python 新手,试图将一些复杂的数据结构存储/检索到文件中,并且正在试验酸洗。但是,下面的示例不断创建一个空白文件(那里没有存储任何内容),我在第二步中遇到了错误。我一直在谷歌搜索,只是为了找到与我的完全匹配的其他示例 - 然而,它似乎不起作用。我可能缺少什么?提前tx!

import pickle

messageToSend = ["Pickle", "this!"]
print("before: \n",messageToSend)

f = open("pickletest.pickle","wb")
pickle.dump(messageToSend,f)
f.close

g = open("pickletest.pickle","rb")
messageReceived = pickle.load(g)
print("after: \n",messageReceived)
g.close
Run Code Online (Sandbox Code Playgroud)

pickle python-3.x

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

在C#中返回字典值而不将其赋值给变量?

我想使用字典的值而不将其赋值给变量:

Dictionary<int, string> LayoutByID = new Dictionary<int, string>() {
    { 0, "foo"},
    { 1, "bar"}
    // ...
};
Run Code Online (Sandbox Code Playgroud)

我可以为例如在创建变量时打印值:

string b;
LayoutByID.TryGetValue(1,out b);
print("Trying Dictionary to retrieve value for 1: " + b);
Run Code Online (Sandbox Code Playgroud)

但我想知道是否有更简单的方法,例如:

print("Trying Dictionary to retrieve value for 1: " + LayoutByID.TryGetValue(1 [???]));
Run Code Online (Sandbox Code Playgroud)

我知道我可以编写一个带有开关的函数,它的工作方式类似,但是使用Dictionaries可能会更便宜,因为我有一个更长的列表.谢谢你的建议!

c# dictionary

0
推荐指数
1
解决办法
814
查看次数

标签 统计

python-3.x ×2

c# ×1

dictionary ×1

multiprocessing ×1

pickle ×1