Skip to content

Commit dd6697a

Browse files
authored
Merge pull request #1217 from iceljc/master
revert code with lock
2 parents bdb7d18 + cf9b7fa commit dd6697a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class PyCodeInterpreter : ICodeProcessor
1313
private readonly IServiceProvider _services;
1414
private readonly ILogger<PyCodeInterpreter> _logger;
1515
private readonly CodingSettings _settings;
16-
private static SemaphoreSlim _semLock = new(initialCount: 1, maxCount: 1);
16+
private static readonly SemaphoreSlim _semLock = new(initialCount: 1, maxCount: 1);
1717

1818
public PyCodeInterpreter(
1919
IServiceProvider services,
@@ -95,6 +95,7 @@ public async Task<CodeGenerationResult> GenerateCodeScriptAsync(string text, Cod
9595
private CodeInterpretResponse InnerRunWithLock(string codeScript, CodeInterpretOptions? options = null, CancellationToken cancellationToken = default)
9696
{
9797
var lockAcquired = false;
98+
9899
try
99100
{
100101
_semLock.Wait(cancellationToken);
@@ -103,7 +104,7 @@ private CodeInterpretResponse InnerRunWithLock(string codeScript, CodeInterpretO
103104
}
104105
catch (Exception ex)
105106
{
106-
_logger.LogError(ex, $"Error in {nameof(InnerRunWithLock)}");
107+
_logger.LogError(ex, $"Error in {nameof(InnerRunWithLock)} in {Provider}");
107108
return new() { ErrorMsg = ex.Message };
108109
}
109110
finally
@@ -157,6 +158,8 @@ private CodeInterpretResponse CoreRunScript(string codeScript, CodeInterpretOpti
157158

158159
var execTask = Task.Factory.StartNew(() =>
159160
{
161+
Thread.Sleep(100);
162+
160163
// For observation purpose
161164
var requestId = Guid.NewGuid();
162165
_logger.LogWarning($"Before acquiring Py.GIL for request {requestId}");

0 commit comments

Comments
 (0)