`ReadOnlyMemoryError` in PyCall

Hi all :slight_smile:

I get some wired ReadOnlyMemoryError on a beefy windows machine. I’m using PyCall to fetch data from Snowflake. Any idea why this sometimes happens?

Cheers

ReadOnlyMemoryError()
Stacktrace:
  [1] macro expansion
    @ C:\.julia\packages\PyCall\BD546\src\exception.jl:95 [inlined]
  [2] #107
    @ C:\.julia\packages\PyCall\BD546\src\pyfncall.jl:43 [inlined]
  [3] disable_sigint
    @ .\c.jl:458 [inlined]
  [4] __pycall!
    @ C:\.julia\packages\PyCall\BD546\src\pyfncall.jl:42 [inlined]
  [5] _pycall!(ret::PyCall.PyObject o::PyCall.PyObject args::Tuple{} nargs::Int64 kw::PyCall.PyObject)
    @ PyCall C:\.julia\packages\PyCall\BD546\src\pyfncall.jl:29
  [6] _pycall!
    @ C:\.julia\packages\PyCall\BD546\src\pyfncall.jl:11 [inlined]
  [7] (::PyCall.PyObject)(; kwargs::Base.Iterators.Pairs{Symbol String NTuple{5 Symbol} NamedTuple{(:user :password :account :warehouse :role) NTuple{5 String}}})
    @ PyCall C:\.julia\packages\PyCall\BD546\src\pyfncall.jl:86
  [8] receive(sql_command::String)
    @ Main.Snowflake \<user>\shared$\TrinityAPI\Ressource\Packages\julia\Snowflake\src\Snowflake.jl:26
  [9] get_NMS_symbol()
    @ Main.ProjectName.SnowflakeManager \<user>\shared$\TrinityAPI\Ressource\Projects\julia\project_name\src\utils\snowflake_manager.jl:102
 [10] start(; is_failover::Bool)
    @ Main.ProjectName \<user>\shared$\TrinityAPI\Ressource\Projects\julia\project_name\src\ProjectName.jl:20
 [11] top-level scope
    @ \<user>\shared$\TrinityAPI\Ressource\Projects\julia\project_name\project_name.jl:7
 [12] include(mod::Module _path::String)
    @ Base .\Base.jl:386
 [13] exec_options(opts::Base.JLOptions)
    @ Base .\client.jl:285
 [14] _start()
    @ Base .\client.jl:485

It’s impossible to help without a MWE, please see point 4 here: Please read: make it easier to help you

const SNOWFLAKE = PyNULL()

function __init__()
    copy!(SNOWFLAKE, pyimport("snowflake.connector"))
end


function receive(
    sql_command::String,
)::DataFrame
    result = DataFrame()
    try
        ctx = SNOWFLAKE.connect(
            user =  Settings.user(), 
            password =  Settings.password(), 
            account = Settings.account(),
            warehouse = Settings.warehouse(),
            role = Settings.role()
        )

        try
            cs = ctx.cursor()
            try
                cs.execute(sql_command)
                data = cs.fetchall()
                if data != Any[]
                    result = DataFrame(data)
                end
            catch e 
                TrinityApi.Logging.error(
                    sprint(showerror, e, catch_backtrace()),
                    "Snowflake.jl InnerInner try"
                )
                rethrow() 
            finally
                cs.close()
            end
        catch e 
            TrinityApi.Logging.error(
                sprint(showerror, e, catch_backtrace()),
                "Snowflake.jl Inner try"
            )
            rethrow()
        finally
            ctx.close()
        end
    catch e 
        TrinityApi.Logging.error(
            sprint(showerror, e, catch_backtrace()),
            "Snowflake.jl Outer try"
        )
        rethrow()
    end

    return result
end 

That’s not a MWE, it needs to be a self-contained piece of code which reproduces the problem. Please read point 4 again.

I’m not being pedantic - giving a MWE makes it a lot easier for people to help you.

1 Like

You are right!!! But I can’t share the whole thing because it’s from work.

That’s where Minimal gets into the picture. Remove everything that’s irrelevant to causing the error. Once you’re done the problem has either become obvious or small enough that its proprietary nature is no longer a problem.

1 Like

My guess is ODBC & Windows is involved

Try a new connection every time instead of re-using connections and you should see it go away