Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on resuming during program run (16.12 regression) #30

Closed
robhagemans opened this issue Mar 11, 2017 · 8 comments
Closed

Crash on resuming during program run (16.12 regression) #30

robhagemans opened this issue Mar 11, 2017 · 8 comments
Assignees
Labels
Projects

Comments

@robhagemans
Copy link
Owner

10 for i = 1to 10000:print i: next

Ctrl+C during run

./pcbasic.py --resume
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/rob/Projects/basic-project/pc-basic/pcbasic/main.py", line 157, in run_session
    session = state.zunpickle(state_file).attach(iface)
  File "/home/rob/Projects/basic-project/pc-basic/pcbasic/state.py", line 82, in zunpickle
    return pickle.loads(zlib.decompress(f.read()))
TypeError: Required argument 'object' (pos 1) not found
@robhagemans robhagemans self-assigned this Mar 11, 2017
@robhagemans robhagemans added this to TODO in 16.12rc1 Mar 11, 2017
@robhagemans
Copy link
Owner Author

This may have to do with the inability to pickle memoryview objects, see https://bugs.python.org/issue27098

@robhagemans
Copy link
Owner Author

  • Does not happen if we simply define a variable i.
  • Does not happen if we allow the program to finish and then exit.
  • Does happen if we include a STOP statement and exit after the break.
  • Also happens if we interrupt PC-BASIC with Alt+F4 while the program is running.

@robhagemans
Copy link
Owner Author

Another suspect is the ByteStream class which is derived from _pyio.BytesIO

@robhagemans
Copy link
Owner Author

10 i=1: goto 10 does not have the issue. FOR loops only?

@robhagemans
Copy link
Owner Author

interpreter.py lines 385, 386:

        counter_view = self._scalars.view(varname)
        self.for_stack.append((varname, counter_view, stop, step, step.sign(), forpos, nextpos,))

This stores a view in a structure that is to be pickled - may be the cause?

@robhagemans robhagemans moved this from TODO to In progress in 16.12rc1 Mar 19, 2017
@robhagemans
Copy link
Owner Author

The memoryview is the issue. Apparently I'm storing most variables simply as bytearrays, but in a FOR-loop I'm keeping a copy of the Value object, which contains a memoryview. Adding __setstate__ and __getstate__ to Value to convert the memoryview to bytearray and back avoids the crash, but cuts the connection between the loop variable and the view of it which is being incremented.

@robhagemans
Copy link
Owner Author

As far as I can see, the loop record contains the Value objects counter_view, stop and step. Not sure why the Scalars object itself pickles without problems in the absence of a FOR-loop.

robhagemans added a commit that referenced this issue Dec 28, 2017
…tearray.

note that this breaks the link of any stored view to the original variable when unpickling.
remove stored view from FOR-stack.
(fix issue #30)
@robhagemans
Copy link
Owner Author

Fixed by 35e5640

@robhagemans robhagemans moved this from In progress to Resolved in 16.12rc1 Dec 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
16.12rc1
Resolved
Development

No branches or pull requests

1 participant