小编ilp*_*omo的帖子

如何在IPython控制台中默认运行文件而不是终端?

我在PyCharm开始了一个新项目.我安装了Anaconda 3.6.所以,在PyCharm中,我选择了Anaconda python.exe作为项目解释器.

当我第一次运行PyCharm时,它使用IPython控制台作为"默认"控制台来运行我的脚本.然后我重新启动了我的PC,现在PyCharm在我运行脚本时使用了终端.为什么?我不想使用来自Anaconda Spyder IDE的终端.我习惯了IPython,我喜欢它,我想用它.

如何完全禁用终端并仅使用IPython控制台?

python ipython pycharm

20
推荐指数
2
解决办法
2万
查看次数

dask.multiprocessing或pandas + multiprocessing.pool:有什么区别?

我正在开发一种用于财务目的的模型。我将整个S&P500组件放在一个文件夹中,其中存储了许多.hdf文件。每个.hdf文件都有其自己的多索引(年-周-分钟)。

顺序代码示例(非并行化):

import os
from classAsset import Asset


def model(current_period, previous_perdiod):
    # do stuff on the current period, based on stats derived from previous_period
    return results

if __name__ == '__main__':
    for hdf_file in os.listdir('data_path'):
        asset = Asset(hdf_file)
        for year in asset.data.index.get_level_values(0).unique().values:
            for week in asset.data.loc[year].index.get_level_values(0).unique().values:

                previous_period = asset.data.loc[(start):(end)].Open.values  # start and end are defined in another function
                current_period = asset.data.loc[year, week].Open.values

                model(current_period, previous_period)
Run Code Online (Sandbox Code Playgroud)

为了加快处理过程,我使用multiprocessing.pool在多个.hdf文件上同时运行相同的算法,因此我对处理速度非常满意(我有一个4c / 8t CPU)。但是现在我发现了Dask。

Dask文档的“ DataFrame概述”中,它们指示:

几乎可并行化的操作(快速)

  • 元素运算:df.x + df.y,df * df
  • 按行选择:df [df.x> …

python multithreading multiprocessing pandas dask

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

如何在单独的进程中运行 Python 自定义对象,所有进程都在共享事件队列上工作?

我有 4 个不同的 Python 自定义对象和一个事件队列。每个 obect 都有一个方法,允许它从共享事件队列中检索事件,如果类型是所需的,则处理它,然后将新事件放在同一个事件队列中,允许其他进程处理它。

这是一个例子。

import multiprocessing as mp

class CustomObject:

    def __init__(events_queue: mp.Queue) -> None:
        self.events_queue = event_queue

    def process_events_queue() -> None:
        event = self.events_queue.get()
        if type(event) == SpecificEventDataTypeForThisClass:
            # do something and create a new_event
            self.events_queue.put(new_event)
        else:
            self.events_queue.put(event)

    # there are other methods specific to each object
Run Code Online (Sandbox Code Playgroud)

这 4 个对象有特定的任务要做,但它们都共享相同的结构。由于我需要“模拟”生产条件,我希望它们同时运行,彼此独立。

如果可能的话,这只是我想做的一个例子。

import multiprocessing as mp
import CustomObject

if __name__ == '__main__':

    events_queue = mp.Queue()

    data_provider = mp.Process(target=CustomObject, args=(events_queue,))
    portfolio = mp.Process(target=CustomObject, args=(events_queue,))
    engine = mp.Process(target=CustomObject, …
Run Code Online (Sandbox Code Playgroud)

python multiprocessing

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