GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stdlib: data race importing a CodeSrc module from several contexts · Issue #266 · go-python/gpython

stdlib: data race importing a CodeSrc module from several contexts #266

New issue
Copy link
New issue
Copy link
Open
#268
Open
stdlib: data race importing a CodeSrc module from several contexts#266
#268
Copy link

Description

@drew-512
drew-512
opened on Nov 10, 2026
Issue body actions

A ModuleImpl registered with CodeSrc (or CodeBuf) is compiled into impl.Code on first import, with no locking (ModuleInit in stdlib/stdlib.go). A registered ModuleImpl is shared by every py.Context, so contexts that import it for the first time at once race on impl.Code and on the py.Code being built.

Reproducer, run with go test -race:

func TestConcurrentCodeSrc(t *testing.T) {
	py.RegisterModule(&py.ModuleImpl{
		Info:    py.ModuleInfo{Name: "codesrc_test", FileDesc: "<codesrc_test>"},
		CodeSrc: "X = 42\n",
	})
	var wg sync.WaitGroup
	for i := 0; i < 8; i++ {
		wg.Add(1)
		go func() {
			defer wg.Done()
			ctx := py.NewContext(py.DefaultContextOpts())
			defer ctx.Close()
			if err := py.Import(ctx, "codesrc_test"); err != nil {
				t.Error(err)
			}
		}()
	}
	wg.Wait()
}

On main (444ae5e) each run reports WARNING: DATA RACE (12–13 reports per run).

Go 1.27.1, darwin/arm64.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.