busylight icon indicating copy to clipboard operation
busylight copied to clipboard

[BUG] No current event loop in thread "Dummy-1".

Open robbyfrt opened this issue 10 months ago • 7 comments

Software Versions:

  • Operating System: Ubuntu 20.02 inside docker on arm64
  • Python version: 3.8.10
  • BusyLight version: 0.26.1

General Type of Problem

  • [x ] Integrating into another project

Describe the Problem

So a simple script works great:

from busylight.lights.kuando import Busylight_Alpha

class Alarm:
    def __init__(self):
        self.light = Busylight_Alpha.first_light(reset=True, exclusive=True)
        self.traffic_colors = [(255,0,0), (255,255,0), (0,255,0)]

    def on_for_25(self, color_id: int):
        self.light.on(self.traffic_colors[color_id])

if __name__ == "__main__":
    alarm = Alarm()
    alarm.on_for_25(color_id=0)

However, using this simple class in a more complex software however returns the error shown below.

I am calling light.on() inside a callback function of a gstreamer pipeline, which was written using python bindings. I have no idea how gstreamer itself generates its threads. I am using it inside a callback similar to this: deepstream_test_1.py -Line 71

It may be easier for me to use lower level functionality for simply turning the light on for some time, but I am unsure where to start in your repo.

Use Case: I simply want to turn my busylight on when my script hast detected some activity. Your api seemed quite straighforward for that.

Expected Behavior What you expected to happen.

Error Output

Traceback (most recent call last):
  File "run.py", line 105, in osd_sink_pad_buffer_probe
    alarm.on_for_25(color_id=0)
  File "<rootdir>/pipeline/common/io.py", line 9, in on_for_25
    self.light.on(self.traffic_colors[color_id])
  File "/usr/local/lib/python3.8/dist-packages/busylight/lights/kuando/busylight_alpha.py", line 50, in on
    self.add_task("keepalive", _keepalive)
  File "/usr/local/lib/python3.8/dist-packages/busylight/lights/taskable.py", line 51, in add_task
    self.tasks[name] = self.event_loop.create_task(coroutine(self))
  File "/usr/local/lib/python3.8/dist-packages/busylight/lights/taskable.py", line 21, in event_loop
    self._event_loop = asyncio.get_event_loop()
  File "/usr/lib/python3.8/asyncio/events.py", line 639, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Dummy-1'.

robbyfrt avatar Aug 30 '23 13:08 robbyfrt