question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

strange behavior with cell

See original GitHub issue

It might be an ipython issue or something… but for me it is highly puzzling.

Problem Description

Here is a reproducible example

from math import sqrt

# %% 
# run this cell before the file, it will normally crashed (lack of sqrt)
# then run whole file
# then call in ipython console: foo2(); print(x)
# x is still 1 !!!

def foo1():
  global x
  x=sqrt(1)

def foo2():
  global x
  x=sqrt(4)

foo1()

What steps reproduce the problem?

  1. run the cell 1st, will normally crash
  2. run the file
  3. call in the console: foo2()
  4. print(x)

What is the expected output? What do you see instead?

‘x’ should be 2, while ‘x’ is still 1

if one reruns the cell, then now it is fine. It is like there are different namespaces or globals for cells ??? It is weird and sources of crazy bugs. Thanks. I guess I’ve default settings in ‘run’ & ‘python interpreter’.

Versions

  • Spyder version: 6.0.0.dev0 48b930506
  • Python version: 3.8.9 64-bit
  • Qt version: 5.15.2
  • PyQt5 version: 5.15.4
  • Operating System: Windows 10

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:24 (24 by maintainers)

github_iconTop GitHub Comments

2reactions
sylvain-bougnouxcommented, Aug 12, 2021

Thanks for these observations & your interest. Yes checking option 2 in ‘run’ does the job. But I am wondering what the opposite (option 2 not checked) means for cells?

My naive understanding of running a cell is: just populate/update the console namespace with the content of the cell; while a file could be seen as a list of cells (with different inputs or knowledge depending on the run option above). If it does something else, it should be stated clearly I guess.

IMHO, there is still a bug when option 2 is unchecked. I’ve found out that even running the file to start with (instead of the cell first) leads to the same problem ; and removing the cell ie ‘# %%’ does not help. It might be due to declaring the variable x from the functions and not from the global namespace ???

But indeed, checking option 2, solves all these experiments, which is even weirder when starting from scratch (because the console is empty anyway!).

Thanks.

1reaction
impact27commented, Jan 11, 2022

Maybe we could simply add a warning when someone runs code in an empty namespace that contains “global”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strange behavior: New study exposes living cells to ... - Phys.org
Strange behavior: New study exposes living cells to synthetic protein. John Chaput is a researcher in ASU's Biodesign institute Photo by: ...
Read more >
Strange behavior: new study exposes living cells to synthetic ...
Strange behavior: new study exposes living cells to synthetic protein ... Inside the cell, DX proteins bind with molecules of ATP, ...
Read more >
EXCEL 365: Filtered view, strange behavior.
When in filtered view I have noticed 3 issues. 1. One cannot just copy some cells from a coloumn into a sheet with...
Read more >
AN UNUSUAL BEHAVIOR OF STRAIN HELA CELLS ... - NCBI
J Cell Biol. ... AN UNUSUAL BEHAVIOR OF STRAIN HELA CELLS IN TISSUE CULTURE ... A description of cellular emigration of embryo chick-leg...
Read more >
Excel Vba Abnormal Behavior of Cells.Find on Merged Cells
The abnormal behavior I'm experiencing is that Find always returns the cell as Nothing on my second call of the sub (The cells...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found