Skip to content

Commit 333807c

Browse files
author
Jicheng Lu
committed
revert
1 parent 2079ba3 commit 333807c

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/Infrastructure/BotSharp.Abstraction/CodeInterpreter/Models/CodeInterpretOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ public class CodeInterpretOptions
66
{
77
public string? ScriptName { get; set; }
88
public IEnumerable<KeyValue>? Arguments { get; set; }
9+
public bool UseMutex { get; set; }
910
public CancellationToken? CancellationToken { get; set; }
1011
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import argparse
2+
import json
23

34
def main():
45
parser = argparse.ArgumentParser(description="Receive named arguments")
56
parser.add_argument("--first_name", required=True, help="The first name")
67
parser.add_argument("--last_name", required=True, help="The last name")
78

8-
args = parser.parse_args()
9-
print(f"Hello, {args.first_name} {args.last_name}!")
9+
args, _ = parser.parse_known_args()
10+
obj = {
11+
"first_name": args.first_name,
12+
"last_name":args.last_name
13+
}
14+
print(f"{json.dumps(obj)}")
1015

1116
if __name__ == "__main__":
1217
main()

src/Plugins/BotSharp.Plugin.PythonInterpreter/Services/PyInterpretService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using BotSharp.Core.CodeInterpreter;
22
using Microsoft.Extensions.Logging;
33
using Python.Runtime;
4+
using System.Threading;
45
using System.Threading.Tasks;
56

67
namespace BotSharp.Plugin.PythonInterpreter.Services;
@@ -25,6 +26,13 @@ public PyInterpretService(
2526

2627
public async Task<CodeInterpretResult> RunCode(string codeScript, CodeInterpretOptions? options = null)
2728
{
29+
if (options?.UseMutex == true)
30+
{
31+
return await _executor.Execute(async () =>
32+
{
33+
return InnerRunCode(codeScript, options);
34+
}, cancellationToken: options?.CancellationToken ?? CancellationToken.None);
35+
}
2836
return InnerRunCode(codeScript, options);
2937
}
3038

0 commit comments

Comments
 (0)