# SymPy makes REPL to stuck

**URL:** https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814
**Category:** General Usage
**Tags:** repl, sympy
**Created:** [January 16, 2025, 1:14am UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814 "2025-01-16T01:14:53Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Xing\_Shi\_Cai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xing_shi_cai/32/14128_2.png) [@Xing\_Shi\_Cai](https://discourse.julialang.org/u/Xing_Shi_Cai)
#### Post date: [January 16, 2025, 1:14am UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/1 "2025-01-16T01:14:53Z")

</div>

When I tried the following in REPL, it gets stuck when I types the last line. I cannot keep typing. The command `top` shows that Julia is using all the CPU. Any suggestion on how to trouble shoot the problem?

I thought it might be due to the fact that I am using kitty terminal emulator. However, other terminal emulators have the same issue.

Also, it seems that running SymPy.jl code as a script does not have this issue.

```julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.11.2 (2024-12-01)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> using SymPy

julia> @syms n
(n,)

julia> ex = 1/(n*(n+3))
    1    
─────────
n⋅(n + 3)

julia> sympy.apart(e

```

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [January 16, 2025, 2:20am UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/2 "2025-01-16T02:20:13Z")

</div>

Installed SymPy to check, happens to me too. The middle lines weren’t needed, anything typed after just `using SymPy` and `sympy.apart(` freezes the REPL. Windows Task Manager doesn’t say Julia is using all the CPU though. I have no earthly idea why writing a partial function call would freeze on a non-space character, and I’m very curious. Other properties freeze upon the parentheses too:

```julia
julia> sympy.apart
Callable SymPy method

julia> sympy.sin
Callable SymPy method

julia> sympy.cos( a

```

In any case, `SymPy.apart` or just `apart` (because it’s exported) works [as documented](https://jverzani.github.io/SymPyCore.jl/dev/introduction/#Rational-expressions:-apart,-together,-cancel):

```julia
julia> using SymPy

julia> @syms n
(n,)

julia> ex = 1/(n*(n+3))
    1
─────────
n⋅(n + 3)

julia> apart(ex)
      1 1
- ───────── + ───
  3⋅(n + 3) 3⋅n

```

To use properties of `sympy`, I could work around the freezing by assigning the property access to another variable, then doing the call separately:

```julia
julia> a = sympy.apart; a(ex) # note: different object from SymPy.apart
      1 1
- ───────── + ───
  3⋅(n + 3) 3⋅n

julia> let b = sympy.apart; b(ex) end # local variable works too, preferred
      1 1
- ───────── + ───
  3⋅(n + 3) 3⋅n

```

or avoiding function call syntax via the 1-argument piping operator:

```julia
julia> ex |> sympy.apart
      1 1
- ───────── + ───
  3⋅(n + 3) 3⋅n

```

or writing it in a string to be parsed and evaluated (`@eval` call or quoted expressions freeze):

```julia
julia> eval(Meta.parse("sympy.apart(ex)"))
      1 1
- ───────── + ───
  3⋅(n + 3) 3⋅n

```

Hopefully someone knows why the REPL would freak out at these particular calls in source or quoted expressions after `SymPy` is imported.

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [January 16, 2025, 5:29am UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/3 "2025-01-16T05:29:47Z")

</div>

My guess is that it’s the the REPL autocomplete code that is trying to obtain possible completions from the `sympy` object that is causing the issue. Can the autocomplete be turned off somehow?

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [January 16, 2025, 8:08am UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/4 "2025-01-16T08:08:55Z")

</div>

You could also try Julia 1.10 …

---

<div class="post-metadata">

### Author: ![Xing\_Shi\_Cai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xing_shi_cai/32/14128_2.png) [@Xing\_Shi\_Cai](https://discourse.julialang.org/u/Xing_Shi_Cai)
#### Post date: [January 16, 2025, 8:49am UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/5 "2025-01-16T08:49:03Z")

</div>

Yes. Julia 1.10 does not have this issue.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [January 16, 2025, 9:56am UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/7 "2025-01-16T09:56:21Z")

</div>

Possibly related: [REPL hints and tab completion freezes the REPL · Issue #55434 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/55434)

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [January 16, 2025, 10:30am UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/8 "2025-01-16T10:30:29Z")

</div>

Confirmed related, disabling the v1.11 REPL hinting in one of the ways that issue linked makes this go away for me, and re-enabling the hinting brings back the freeze. Before it did, using the up-arrow to find and rerun the line worked fine.

```julia
julia> Base.active_repl.options.hint_tab_completes = false
false

julia> sympy.apart(ex)
      1 1
- ───────── + ───
  3⋅(n + 3) 3⋅n

julia> Base.active_repl.options.hint_tab_completes = true
true

julia> sympy.apart(ex) # up-arrow to previous line
      1 1
- ───────── + ───
  3⋅(n + 3) 3⋅n

julia> sympy.apart(e

```

I’m surprised that hinting does type inference for an incomplete call, I thought it would only need to search the scopes for names. This also doesn’t explain why the `a = sympy.apart; a(ex)` workaround worked; does REPL hinting just not bother inferring `a(e` there? Whatever it does, I’d definitely want it to give up right after I type another character, on a single thread too.

---

<div class="post-metadata">

### Author: ![Xing\_Shi\_Cai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xing_shi_cai/32/14128_2.png) [@Xing\_Shi\_Cai](https://discourse.julialang.org/u/Xing_Shi_Cai)
#### Post date: [January 17, 2025, 11:55am UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/9 "2025-01-17T11:55:11Z")

</div>

I have added this to `~/.julia/confg/startup.jl`

```julia
atreplinit() do repl
    # Turn off hint in Julia 1.11 to deal with SymPy problem
    Base.active_repl.options.hint_tab_completes = false
end

```

---

<div class="post-metadata">

### Author: ![ianshmean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ianshmean/32/216042_2.png) [@ianshmean](https://discourse.julialang.org/u/ianshmean)
#### Post date: [January 20, 2025, 7:40pm UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/10 "2025-01-20T19:40:48Z")

</div>

Please check the [pre-release of v1.11.3](https://discourse.julialang.org/t/julia-v1-11-3-testing-period/124787/2) (or julia nightly) as this should be fixed there (and save having to disable hints)

---

<div class="post-metadata">

### Author: ![ianshmean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ianshmean/32/216042_2.png) [@ianshmean](https://discourse.julialang.org/u/ianshmean)
#### Post date: [January 20, 2025, 7:41pm UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/11 "2025-01-20T19:41:53Z")

</div>

Specifically [Very sluggish autocomplete with PyCall · Issue #54131 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/54131) was the issue that has been fixed.

---

<div class="post-metadata">

### Author: ![Xing\_Shi\_Cai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xing_shi_cai/32/14128_2.png) [@Xing\_Shi\_Cai](https://discourse.julialang.org/u/Xing_Shi_Cai)
#### Post date: [January 23, 2025, 3:45am UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/12 "2025-01-23T03:45:28Z")

</div>

The freezing issue has been resolved. However, we get another problem

```julia
julia> using SymPy
Precompiling SymPy...
  19 dependencies successfully precompiled in 11 seconds. 33 already precompiled.

julia> sympy.apart(33/4)
8.25000000000000

julia> @syms n
(n,)

julia> ex = 1/(n*(n+3))
    1    
─────────
n⋅(n + 3)

julia> sympy.apart(e┌ Error: Error in the keymap
│ exception =
│ TypeError: in typeassert, expected REPL.REPLCompletions.MethodCompletion, got a value of type REPL.REPLCompletions.TextCompletion
│ Stacktrace:
│ [1] complete_keyword_argument
│ @ ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPLCompletions.jl:1040
│ [2] completions(string::String, pos::Int64, context_module::Module, shift::Bool, hint::Bool)
│ @ REPL.REPLCompletions ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPLCompletions.jl:1379
│ [3] complete_line(c::REPL.REPLCompletionProvider, s::REPL.LineEdit.PromptState, mod::Module; hint::Bool)
│ @ REPL ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/REPL.jl:637
│ [4] #complete_line#14
│ @ ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:428
│ [5] complete_line
│ @ ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:427
│ [6] complete_line
│ @ ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:369
│ [7] edit_tab (repeats 2 times)
│ @ ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:2419
│ [8] #118
│ @ ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:2465
│ [9] #invokelatest#2
│ @ ./essentials.jl:1055 [inlined]
│ [10] invokelatest
│ @ ./essentials.jl:1052 [inlined]
│ [11] #30
│ @ ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:1711
│ [12] macro expansion
│ @ ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:2861 [inlined]
│ [13] macro expansion
│ @ ./lock.jl:273 [inlined]
│ [14] #282
│ @ ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:2851
└ @ REPL.LineEdit ~/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:2863

```

---

<div class="post-metadata">

### Author: ![ianshmean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ianshmean/32/216042_2.png) [@ianshmean](https://discourse.julialang.org/u/ianshmean)
#### Post date: [January 23, 2025, 5:22am UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/13 "2025-01-23T05:22:29Z")

</div>

Odd that this issue wasn’t caught by the local testing in [REPL: Limit method lookup when completing kwargs by IanButterworth · Pull Request #56963 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/56963#issuecomment-2572338231)

Can you try [REPL: Handle message from `complete_methods!` when max methods is hit by IanButterworth · Pull Request #57138 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/57138)  
i.e. `juliaup add pr57138` once that’s got green tests

---

<div class="post-metadata">

### Author: ![Xing\_Shi\_Cai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xing_shi_cai/32/14128_2.png) [@Xing\_Shi\_Cai](https://discourse.julialang.org/u/Xing_Shi_Cai)
#### Post date: [January 23, 2025, 8:30am UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/14 "2025-01-23T08:30:11Z")

</div>

OK. But I will need to figure out how to use run Julia modified with pull requests.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [January 23, 2025, 9:19am UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/15 "2025-01-23T09:19:46Z")

</div>

```julia
ufechner@framework:~$ juliaup add pr57138
Installing Julia pr57138-linux-x86_64
ufechner@framework:~$ julia +pr57138
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.12.0-DEV.1927 (2025-01-23)
 _/ |\ __'_|_|_|\__'_| | IanButterworth:ib/repl_completion_fix/1a469315033 (fork: 1 commits, 0 days)
|__/ |

```

So easy…

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [January 23, 2025, 9:30am UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/16 "2025-01-23T09:30:11Z")

</div>

Strange, I was spared on v1.11.3 for that example. Could it be platform-dependent, I’m on Windows.

```julia
julia> sympy.apart(33/4)
8.25000000000000

julia> @syms n
(n,)

julia> ex = 1/(n*(n+3))
    1
─────────
n⋅(n + 3)

julia> sympy.apart(ex)
      1 1
- ───────── + ───
  3⋅(n + 3) 3⋅n

```

EDIT: yes, hitting TAB gets me the error

---

<div class="post-metadata">

### Author: ![Xing\_Shi\_Cai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xing_shi_cai/32/14128_2.png) [@Xing\_Shi\_Cai](https://discourse.julialang.org/u/Xing_Shi_Cai)
#### Post date: [January 23, 2025, 1:59pm UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/17 "2025-01-23T13:59:26Z")

</div>

It happens when I type `sympy.apart(e` and hit `Tab`.

Applying the patch pull request above **does** fix the problem!

---

<div class="post-metadata">

### Author: ![ianshmean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ianshmean/32/216042_2.png) [@ianshmean](https://discourse.julialang.org/u/ianshmean)
#### Post date: [January 23, 2025, 2:08pm UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/18 "2025-01-23T14:08:14Z")

</div>

Please comment on the [PR](https://github.com/JuliaLang/julia/pull/57138) with your reproducer, errors and versioninfo

---

<div class="post-metadata">

### Author: ![Xing\_Shi\_Cai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xing_shi_cai/32/14128_2.png) [@Xing\_Shi\_Cai](https://discourse.julialang.org/u/Xing_Shi_Cai)
#### Post date: [January 23, 2025, 2:43pm UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/19 "2025-01-23T14:43:47Z")

</div>

Ah, I am not sure what “reproducer” mean.

---

<div class="post-metadata">

### Author: ![ianshmean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ianshmean/32/216042_2.png) [@ianshmean](https://discourse.julialang.org/u/ianshmean)
#### Post date: [January 23, 2025, 2:46pm UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/20 "2025-01-23T14:46:20Z")

</div>

Reproducer: [How to create a Minimal, Reproducible Example - Help Center - Stack Overflow](https://stackoverflow.com/help/minimal-reproducible-example)

I now see you have edited your post to say it _has_ fixed the issue for you. So obviously you won’t have errors to add.

---

<div class="post-metadata">

### Author: ![Xing\_Shi\_Cai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xing_shi_cai/32/14128_2.png) [@Xing\_Shi\_Cai](https://discourse.julialang.org/u/Xing_Shi_Cai)
#### Post date: [January 23, 2025, 2:47pm UTC](https://discourse.julialang.org/t/sympy-makes-repl-to-stuck/124814/21 "2025-01-23T14:47:43Z")

</div>

Yes. When I first run it I forgot to use the version with the PR. I noticed this and tried it with the PR. The problem disappears.
