Xilinx / DPU-PYNQ

DPU on PYNQ
Apache License 2.0
202 stars 69 forks source link

RuntimeError: There is no current event loop in thread 'ScriptRunner.scriptThread'. #108

Open manudwd opened 1 year ago

manudwd commented 1 year ago

Hello! DPU Target: DPUCZDX8G_ISA1_B4096

Vitis Verison: 2.5.0 (CPU)

I am using the Xilinx-RFSoC ZCU 111 for a custom neural net, I am using that with combinations to some other tools to create something along the lines of a dash board for my results, all of which is intended to happen on the board using board Jupyter terminal.

I am able to load the bitstream as usual using dpu = DpuOverlay("dpu.bit") when I run it on the jupyter notebook. The problem occurs when I use it in combination with this web app creating tool called streamlit. streamlit hosts on the local system as well typically on localhost:8501 port, while PYNQ hosts on port:8080.

Expected Behaviour: when I run streamlit run myDPU_file.py, the app should be hosted on local computer's browser since the Board is connected to my local computer via UART.

Actual Behaviour: The error message:

RuntimeError: There is no current event loop in thread 'ScriptRunner.scriptThread'.
Traceback:

File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 541, in _run_script
    exec(code, module.__dict__)
File "/home/xilinx/jupyter_notebooks/pynq-dpu/present_Complete_DPU.py", line 394, in <module>
    overlay = DpuOverlay("dpu.bit")
File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq_dpu/dpu.py", line 98, in __init__
    super().__init__(abs_bitfile_name,
File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/overlay.py", line 315, in __init__
    super().__init__(bitfile_name, dtbo, partial=False, device=device)
File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/bitstream.py", line 88, in __init__
    device = Device.active_device
File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/pl_server/device.py", line 70, in active_device
    if len(cls.devices) == 0:
File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/pl_server/device.py", line 54, in devices
    cls._devices.extend(DeviceMeta._subclasses[key]._probe_())
File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/pl_server/embedded_device.py", line 545, in _probe_
    return [EmbeddedDevice()]
File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/pl_server/embedded_device.py", line 568, in __init__
    super().__init__(0, "embedded_xrt{}")
File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/pynq/pl_server/xrt_device.py", line 325, in __init__
    self._loop = asyncio.get_event_loop()
File "/usr/lib/python3.10/asyncio/events.py", line 656, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'

I understand this problem may not be answered since it is raised in combination with other tools, but the error message seems to suggest that no device is found, which shouldn't be the case. It seems like a fundamental problem of threading, any help in diagnosing would be really appreciated.

skalade commented 11 months ago

Hi @manudwd,

Looking at https://github.com/Xilinx/DPU-PYNQ/issues/106 I ran into the exact same error message as you have reported here. In that case vaitrace was destroying the event loop that xrt_device was grabbing. The solution that worked for me was starting a new event loop inside the vaitrace application like so:

import asyncio
asyncio.set_event_loop(asyncio.new_event_loop())

Not very familiar with your application, but maybe it helps. If you resolved your issue another way please share a solution and/or close the issue. Thanks!