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

pypi page example throwing Python-CFFI error and not terminating #223

Open
MichaelQuaMan opened this issue Jan 1, 2023 · 2 comments
Open

Comments

@MichaelQuaMan
Copy link

MichaelQuaMan commented Jan 1, 2023

Summary

  • Initial example code not breaking on Ctrl + c
  • Throwing Python-CFFI error

image

  • Keeps running and need to find and kill the Python process

Expectation

  • Code should probably terminate on Ctrl + c and gracefully close.

Other considerations

  • It would be great if the demo has visual output:
    • there could be a tiny screenshot depicting the expected output
    • maybe a very short description of what the user should expect to see on screen.

Note: I see the code comments and they don't say what I should see on-screen.

So, textual output maybe the only output?

Not sure, but as a user it would be nice to know what to expect before I run the code.

Also, it would be great if
- Ctrl+c worked to break the loop (just for this example) so the user could quickly kill it.

Code

import pymunk  # Import pymunk..

space = pymunk.Space()  # Create a Space which contain the simulation
space.gravity = 0, -981  # Set its gravity

body = pymunk.Body()  # Create a Body
body.position = 50, 100  # Set the position of the body

poly = pymunk.Poly.create_box(body)  # Create a box shape and attach to body
poly.mass = 10  # Set the mass on the shape
space.add(body, poly)  # Add both body and shape to the simulation

print_options = pymunk.SpaceDebugDrawOptions()  # For easy printing

while True:  # Infinite loop simulation
    space.step(0.02)  # Step the simulation one step forward
    space.debug_draw(print_options)  # Print the state of the simulation
@MichaelQuaMan
Copy link
Author

MichaelQuaMan commented Jan 1, 2023

Based on the exception Exception ignored from cffi callback ext_cpSpaceDebugDrawPolygonimpl, looks like the keyboardInterrupt may be ignored on purpose in the underlying C libs.

Maybe the interrupt can be caught in the pythong and call something like sys.exit()

Update

  • if I hit the Ctrl + c several times, from the terminal, it will eventually die.

Note: it still gives and audible warning and throws the CFFI exception in a popup, but it does eventually die.

It just really wants to LIVE! Who can blame it.

@viblo
Copy link
Owner

viblo commented Jan 2, 2023

Oh.. Maybe it would be better to limit the number of loops to 100 or something, to not let the user get trapped?

The reason why the output is text only (while many of the more advanced pymunk examples have more visually interesting output) is that I wanted the readme example to not have any additional dependencies except pymunk. Its also nice that it works directly in the terminal.

I have thought about adding a tkinter drawing module, but Im not sure how useful it would be except to make this initial quick demo in the readme nicer..

(The other examples use pygame, pyglet etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants