🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/runtime/pythonengine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ public static int RunSimpleString(string code)

public static void Initialize()
{
Initialize(Enumerable.Empty<string>());
Initialize(setSysArgv: true);
}

public static void Initialize(bool setSysArgv = true)
{
Initialize(Enumerable.Empty<string>(), setSysArgv: setSysArgv);
}

/// <summary>
Expand All @@ -134,7 +139,7 @@ public static void Initialize()
/// first call. It is *not* necessary to hold the Python global
/// interpreter lock (GIL) to call this method.
/// </remarks>
public static void Initialize(IEnumerable<string> args)
public static void Initialize(IEnumerable<string> args, bool setSysArgv = true)
{
if (!initialized)
{
Expand All @@ -148,7 +153,8 @@ public static void Initialize(IEnumerable<string> args)
initialized = true;
Exceptions.Clear();

Py.SetArgv(args);
if (setSysArgv)
Py.SetArgv(args);

// register the atexit callback (this doesn't use Py_AtExit as the C atexit
// callbacks are called after python is fully finalized but the python ones
Expand Down Expand Up @@ -213,7 +219,7 @@ public static void InitExt()
{
try
{
Initialize();
Initialize(setSysArgv: false);

// Trickery - when the import hook is installed into an already
// running Python, the standard import machinery is still in
Expand Down
3 changes: 0 additions & 3 deletions src/tests/test_sysargv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

import sys

import pytest

from ._compat import check_output


@pytest.mark.xfail(reason="argv being reset on import clr. See gh#404")
def test_sys_argv_state(filepath):
"""Test sys.argv state doesn't change after clr import.
To better control the arguments being passed, test on a fresh python
Expand Down