简体   繁体   English

使用 vs 代码在 wsl 2 ubuntu 上调试 python autosklearn

[英]debugging python autosklearn on wsl 2 ubuntu with vs code

I have a python script using autosklearn.我有一个使用 autosklearn 的 python 脚本。 I am running this under wsl ubuntu 1804, because the package didn't intall in windows.我在wsl ubuntu 1804下运行这个,因为package没有安装在windows中。

I've been running jupyter notebook to create the script initially.我最初一直在运行 jupyter notebook 来创建脚本。 It runs fine in the browser, but in order to go further, I prefer to use vs code.它在浏览器中运行良好,但为了进一步 go,我更喜欢使用 vs 代码。 I installed vs code server, and can debug the script in vscode.我安装了vs code server,可以在vscode中调试脚本。 Initially pylint didn't recognise my autosklearn import.最初 pylint 无法识别我的 autosklearn 导入。 Then I installed the Microsoft python extension on ubuntu, and it was happy.然后我在ubuntu上安装了微软的python扩展,很开心。

I should point out I was previously running jupyter notebook with associated packages from an isolated environment.我应该指出,我之前正在运行 jupyter notebook 以及来自隔离环境的相关包。 I started vscode from within that environment.我从那个环境中开始使用 vscode。

When I debug the script, everything is fine until I get to the line that does the fitting当我调试脚本时,一切都很好,直到我到达进行拟合的行

automl = autosklearn.regression.AutoSklearnRegressor(
                        time_left_for_this_task=360,
                        per_run_time_limit=30,
                        tmp_folder='./autosklearn_regression_example_tmp',
                        output_folder='./autosklearn_regression_example_out',
                        )
automl.fit(X_train, y_train.values.ravel(),
       dataset_name='mytest',
       feat_type=feature_types)

I get this error:我收到此错误:

E00005.591: Exception escaped from start_client

        Traceback (most recent call last):
          File "/home/ubx/.vscode-server/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/old_ptvsd/ptvsd/log.py", line 110, in g
            return f(*args, **kwargs)
          File "/home/ubx/.vscode-server/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/old_ptvsd/ptvsd/pydevd_hooks.py", line 74, in start_client
            sock, start_session = daemon.start_client((host, port))
          File "/home/ubx/.vscode-server/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/old_ptvsd/ptvsd/daemon.py", line 214, in start_client
            with self.started():
          File "/usr/lib/python3.6/contextlib.py", line 81, in __enter__
            return next(self.gen)
          File "/home/ubx/.vscode-server/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/old_ptvsd/ptvsd/daemon.py", line 110, in started
            self.start()
          File "/home/ubx/.vscode-server/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/old_ptvsd/ptvsd/daemon.py", line 145, in start
            raise RuntimeError('already started')
        RuntimeError: already started


Traceback (most recent call last):

Terminated

I've got a feeling that the problem is that microsoft's version of python (which was installed as an extension for vscode) is incompatible with the package.我有一种感觉,问题在于微软的 python 版本(作为 vscode 的扩展安装)与 package 不兼容。 The package still runs fine from within ubuntu jupyter notebook. package 在 ubuntu jupyter notebook 中仍然可以正常运行。

But the error is very odd.但是错误非常奇怪。 I would expect a different error for package incompatibility.我预计 package 不兼容会出现不同的错误。

Any suggestions much appreciated.任何建议都非常感谢。

Martin马丁

The error stack that you're seeing is indicative of the library attempting to fork the process, eg because it's using the standard multiprocessing module internally.您看到的错误堆栈表明库试图分叉该进程,例如因为它在内部使用标准的multiprocessing模块。 The version of ptvsd that you're running it on does not support forking.您运行它的 ptvsd 版本不支持分叉。

If it does indeed use multiprocessing , you should be able to explicitly tell it to use spawn instead of fork in your main script:如果它确实使用了multiprocessing ,你应该能够明确地告诉它在你的主脚本中使用 spawn 而不是 fork :

import multiprocessing

if __name__ == "__main__":
    multiprocessing.set_start_method("spawn")

The part that checks __name__ is important to avoid child processes from running the same line.检查__name__的部分对于避免子进程运行同一行很重要。 A more detailed explanation of various start methods and their gotchas can be found in Python documentation .可以在Python 文档中找到有关各种启动方法及其陷阱的更详细说明。 Note that as of Python 3.8, "spawn" is the default on Windows and MacOS, and "fork" is outright unavailable on the former, and considered broken on the latter - so code that wants to run on all three, and expects consistent behavior, should use "spawn".请注意,从 Python 3.8 开始,“spawn”是 Windows 和 MacOS 上的默认设置,而“fork”在前者上完全不可用,并且在后者上被认为是损坏的 - 所以想要在所有三个上运行的代码,并期望一致的行为,应该使用“spawn”。

The upcoming major revision of ptvsd fully supports forking, but it hasn't been released yet.即将到来的 ptvsd 主要修订版完全支持分叉,但尚未发布。 You can track the progress here .您可以在此处跟踪进度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM