Skip to content

Runloop is not run if body only #631

Description

@melMass

Kind of related to #474

All samples work, but the demo tilt loop is never run. What is strange is that it is blocking the program properly, but even if I print something in the first line of body, I don't see anything

Original Sample
#!/usr/bin/env python
import freenect
import time
import random
import signal

keep_running = True
last_time = 0


def body(dev, ctx):
    global last_time
    if not keep_running:
        raise freenect.Kill
    if time.time() - last_time < 3:
        return
    last_time = time.time()
    led = random.randint(0, 6)
    tilt = random.randint(0, 30)
    freenect.set_led(dev, led)
    freenect.set_tilt_degs(dev, tilt)
    print('led[%d] tilt[%d] accel[%s]' % (led, tilt, freenect.get_accel(dev)))


def handler(signum, frame):
    """Sets up the kill handler, catches SIGINT"""
    global keep_running
    keep_running = False
print('Press Ctrl-C in terminal to stop')
signal.signal(signal.SIGINT, handler)
freenect.runloop(body=body)
Working example if I instance a CV window and use the video callback then the loop is run
#!/usr/bin/env python
import freenect
import time
import random
import signal
import cv2
import frame_convert2

cv2.namedWindow("RGB")
keep_running = True
last_time = 0


def body(*args):
    dev = args[0]
    print("body")
    global last_time
    print(last_time)
    if not keep_running:
        raise freenect.Kill
    if time.time() - last_time < 3:
        return
    last_time = time.time()
    led = random.randint(0, 6)
    tilt = random.randint(0, 30)
    freenect.set_led(dev, led)
    freenect.set_tilt_degs(dev, tilt)
    print("led[%d] tilt[%d] accel[%s]" % (led, tilt, freenect.get_accel(dev)))


def handler(signum, frame):
    """Sets up the kill handler, catches SIGINT"""
    global keep_running
    keep_running = False


def display_rgb(dev, data, timestamp):
    global keep_running
    cv2.imshow("RGB", frame_convert2.video_cv(data))
    if cv2.waitKey(10) == 27:
        keep_running = False


print("Press Ctrl-C in terminal to stop")
signal.signal(signal.SIGINT, handler)
print("Running loop")
freenect.runloop(video=display_rgb, body=body)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions