# \`ReadOnlyMemoryError\` in PyCall

**URL:** <https://discourse.julialang.org/t/readonlymemoryerror-in-pycall/81907>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 30, 2022, 9:29am UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-pycall/81907 "2022-05-30T09:29:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [May 30, 2022, 9:29am UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-pycall/81907/1 "2022-05-30T09:29:48Z")

</div>

Hi all 🙂

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

```julia
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

```

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [May 30, 2022, 10:49am UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-pycall/81907/2 "2022-05-30T10:49:41Z")

</div>

It’s impossible to help without a MWE, please see point 4 here: [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757)

---

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [May 30, 2022, 11:09am UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-pycall/81907/3 "2022-05-30T11:09:20Z")

</div>

```julia
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 

```

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [May 30, 2022, 12:01pm UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-pycall/81907/4 "2022-05-30T12:01:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [May 30, 2022, 1:38pm UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-pycall/81907/5 "2022-05-30T13:38:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [May 30, 2022, 2:02pm UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-pycall/81907/6 "2022-05-30T14:02:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)\
**Post date:** [May 30, 2022, 2:02pm UTC](https://discourse.julialang.org/t/readonlymemoryerror-in-pycall/81907/7 "2022-05-30T14:02:34Z")

</div>

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
