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

Python's GIL should be released when calling ground #82

Closed
rkaminsk opened this issue Jan 17, 2018 · 1 comment
Closed

Python's GIL should be released when calling ground #82

rkaminsk opened this issue Jan 17, 2018 · 1 comment
Assignees
Milestone

Comments

@rkaminsk
Copy link
Member

No description provided.

@rkaminsk rkaminsk self-assigned this Jan 17, 2018
@rkaminsk rkaminsk added this to the v5.3.0 milestone Apr 29, 2018
rkaminsk added a commit that referenced this issue Jun 1, 2018
@rkaminsk
Copy link
Member Author

rkaminsk commented Jun 1, 2018

@javier-romero

Signals in Python are a weird thing. So the code you posted in #83 cannot be made to work. With the above commit the following program can be interrupted:

import clingo
import signal
import sys
import os

from threading import Thread
from time import sleep

def signal_handler(signum, frame):
    print("signal caught")
    os._exit(1)

def ground():
    ctl = clingo.Control()
    ctl.add("base",[],"""
    #const n=500.
    b(1..n,1..n,1..n).
    """)
    ctl.ground([("base",[])])

signal.signal(signal.SIGINT, signal_handler)

thread = Thread(target=ground)
thread.start()
thread.join(float("inf"))

Grounding has to be started in a thread and you have to wait for completion with a timeout. Whether this works also depends on which python/platform you are using. Also note that os_.exit is used instead of sys.exit, which is important because, otherwise, python will wait until grounding completed.

rkaminsk added a commit that referenced this issue Jun 4, 2018
@rkaminsk rkaminsk closed this as completed Jun 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant