Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class PyCodeInterpreter : ICodeProcessor
private readonly IServiceProvider _services;
private readonly ILogger<PyCodeInterpreter> _logger;
private readonly CodingSettings _settings;
private static SemaphoreSlim _semLock = new(initialCount: 1, maxCount: 1);
private static readonly SemaphoreSlim _semLock = new(initialCount: 1, maxCount: 1);

public PyCodeInterpreter(
IServiceProvider services,
Expand Down Expand Up @@ -95,6 +95,7 @@ public async Task<CodeGenerationResult> GenerateCodeScriptAsync(string text, Cod
private CodeInterpretResponse InnerRunWithLock(string codeScript, CodeInterpretOptions? options = null, CancellationToken cancellationToken = default)
{
var lockAcquired = false;

try
{
_semLock.Wait(cancellationToken);
Expand All @@ -103,7 +104,7 @@ private CodeInterpretResponse InnerRunWithLock(string codeScript, CodeInterpretO
}
catch (Exception ex)
{
_logger.LogError(ex, $"Error in {nameof(InnerRunWithLock)}");
_logger.LogError(ex, $"Error in {nameof(InnerRunWithLock)} in {Provider}");
return new() { ErrorMsg = ex.Message };
}
finally
Expand Down Expand Up @@ -157,6 +158,8 @@ private CodeInterpretResponse CoreRunScript(string codeScript, CodeInterpretOpti

var execTask = Task.Factory.StartNew(() =>
{
Thread.Sleep(100);

// For observation purpose
var requestId = Guid.NewGuid();
_logger.LogWarning($"Before acquiring Py.GIL for request {requestId}");
Expand Down
Loading