Skip to content

pandas CANNOT work with multi context due to TypeError: object.init() takes exactly one argument (the instance to initialize) #642

@yandenghui12

Description

@yandenghui12

Describe the bug

pandas CANNOT work with multi context due to TypeError: object.init() takes exactly one argument (the instance to initialize)

Operating system

Linux

CPU architecture

x86_64

GraalPy version

25.0.1

JDK version

graalvm-community-jdk-21.0.2/graalvm-community-openjdk-25.0.2/graalvm-jdk-25.0.2

Context configuration

import lombok.extern.slf4j.Slf4j;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Engine;
import org.graalvm.polyglot.HostAccess;
import org.graalvm.polyglot.Source;

@Slf4j
public class MultiContextTest {
    public static void main(String[] args) {
        Engine sharedEngine = Engine.newBuilder("python")
                .allowExperimentalOptions(true)
                .option("engine.WarnInterpreterOnly", "false")
                .option("engine.Compilation", "true")
                .option("engine.BackgroundCompilation", "true")
                .option("engine.CompileImmediately", "false")
                .option("engine.MultiTier", "true")
                .build();

        String script = " import pandas";
        Source source = Source
                .newBuilder("python", script, "test.py")
                .cached(true)
                .buildLiteral();


        for (int i = 0; i < 2; i++) {
            Context context = createContext(sharedEngine);
            final int index = i;
            Thread.startVirtualThread(() -> {
                try {
                    long preWarmStart = System.currentTimeMillis();
                    context.eval(source);
                    long preWarmEnd = System.currentTimeMillis();
                    log.debug("Context[{}] preheating completed, time cost: {}ms",
                            index, preWarmEnd - preWarmStart);
                } catch (Exception e) {
                    log.error("Failed to preheat Context[{}]", index, e);
                }
            });
        }
    }

    public static Context createContext(Engine sharedEngine) {
        Context context = Context.newBuilder("python")
                .engine(sharedEngine)
                .allowAllAccess(true)
                .allowExperimentalOptions(true)
                .allowNativeAccess(true)
                .allowHostAccess(HostAccess.ALL)
                .allowHostClassLookup(className -> true)
                .allowCreateThread(true)
                .option("python.ForceImportSite", "true")
                .option("python.Executable", "/app/graalpy-25.0.1-linux-amd64/bin/dapvenv/bin/python")
                .option("python.WarnExperimentalFeatures", "false")
                .option("python.IsolateNativeModules", "true")
                .build();

        context.initialize("python");

        return context;
    }

}

Steps to reproduce

run MultiContextTest

Expected behavior

Context[0] preheating completed, time cost: xms
Context[1] preheating completed, time cost: xms

Stack trace

[ERROR] Failed to preheat Context[1]
org.graalvm.polyglot.PolyglotException: TypeError: object.__init__() takes exactly one argument (the instance to initialize)
        at <python>.<module>(b1e1662e6ibey580:1)
        at org.graalvm.polyglot.Context.eval(Context.java:419)
        at com.kingstar.dap.workflow.graal.py.PyContextPool.lambda$preWarmContexts$1(PyContextPool.java:135)
        at com.alibaba.ttl.TtlRunnable.run(TtlRunnable.java:60)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614)
        at java.lang.Thread.run(Thread.java:1474)

[DEBUG] Context[0] preheating completed, time cost: 64398ms

Additional context

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions