小编lmc*_*ory的帖子

Python:如何并行运行python函数?

我先研究过,找不到我的问题的答案.我试图在Python中并行运行多个函数.

我有这样的事情:

files.py

import common #common is a util class that handles all the IO stuff

dir1 = 'C:\folder1'
dir2 = 'C:\folder2'
filename = 'test.txt'
addFiles = [25, 5, 15, 35, 45, 25, 5, 15, 35, 45]

def func1():
   c = common.Common()
   for i in range(len(addFiles)):
       c.createFiles(addFiles[i], filename, dir1)
       c.getFiles(dir1)
       time.sleep(10)
       c.removeFiles(addFiles[i], dir1)
       c.getFiles(dir1)

def func2():
   c = common.Common()
   for i in range(len(addFiles)):
       c.createFiles(addFiles[i], filename, dir2)
       c.getFiles(dir2)
       time.sleep(10)
       c.removeFiles(addFiles[i], dir2)
       c.getFiles(dir2)
Run Code Online (Sandbox Code Playgroud)

我想调用func1和func2并让它们同时运行.这些函数不会相互交互或在同一个对象上交互.现在我必须等待func1在func2启动之前完成.我如何做以下事情:

process.py

from files import func1, func2

runBothFunc(func1(), func2()) …
Run Code Online (Sandbox Code Playgroud)

python

89
推荐指数
6
解决办法
13万
查看次数

使用打字稿在可见网络中设置边缘的问题

我正在关注 vis 的动态数据集示例,当我尝试设置边缘时,我收到了一个打字稿错误。

我只有一个边缘数组,看起来像:

edgesArray = [
 { from: 1, to: 3 },
 { from: 1, to: 2 },
 { from: 2, to: 4 },
 { from: 3, to: 5 },
 ]
Run Code Online (Sandbox Code Playgroud)

我将数据设置为

let data = {
  nodes: new vis.DataSet(nodesArray),
  edges: new vis.DataSet(edgesArray)
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误在边缘。

No overload matches this call.
  Overload 1 of 2, '(options?: DataSetInitialOptions<"id">): DataSet<Partial<Record<"id", string | number>>, "id">', gave the following error.
    Type '{ from: number; to: number; } []' has no properties in common with type …
Run Code Online (Sandbox Code Playgroud)

vis.js visnetwork

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

标签 统计

python ×1

vis.js ×1

visnetwork ×1