This commit is contained in:
Jicheng Lu 2025-10-08 15:25:53 -05:00
parent 2079ba3760
commit 333807ceb7
3 changed files with 16 additions and 2 deletions

View file

@ -6,5 +6,6 @@ public class CodeInterpretOptions
{ {
public string? ScriptName { get; set; } public string? ScriptName { get; set; }
public IEnumerable<KeyValue>? Arguments { get; set; } public IEnumerable<KeyValue>? Arguments { get; set; }
public bool UseMutex { get; set; }
public CancellationToken? CancellationToken { get; set; } public CancellationToken? CancellationToken { get; set; }
} }

View file

@ -1,12 +1,17 @@
import argparse import argparse
import json
def main(): def main():
parser = argparse.ArgumentParser(description="Receive named arguments") parser = argparse.ArgumentParser(description="Receive named arguments")
parser.add_argument("--first_name", required=True, help="The first name") parser.add_argument("--first_name", required=True, help="The first name")
parser.add_argument("--last_name", required=True, help="The last name") parser.add_argument("--last_name", required=True, help="The last name")
args = parser.parse_args() args, _ = parser.parse_known_args()
print(f"Hello, {args.first_name} {args.last_name}!") obj = {
"first_name": args.first_name,
"last_name":args.last_name
}
print(f"{json.dumps(obj)}")
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View file

@ -1,6 +1,7 @@
using BotSharp.Core.CodeInterpreter; using BotSharp.Core.CodeInterpreter;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Python.Runtime; using Python.Runtime;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BotSharp.Plugin.PythonInterpreter.Services; namespace BotSharp.Plugin.PythonInterpreter.Services;
@ -25,6 +26,13 @@ public class PyInterpretService : ICodeInterpretService
public async Task<CodeInterpretResult> RunCode(string codeScript, CodeInterpretOptions? options = null) public async Task<CodeInterpretResult> RunCode(string codeScript, CodeInterpretOptions? options = null)
{ {
if (options?.UseMutex == true)
{
return await _executor.Execute(async () =>
{
return InnerRunCode(codeScript, options);
}, cancellationToken: options?.CancellationToken ?? CancellationToken.None);
}
return InnerRunCode(codeScript, options); return InnerRunCode(codeScript, options);
} }