Skip to content

Signal Module Error in PythonCoderTool During RL Training #30

Description

@zhangxixi551

During our RL training, the following error occurred:

(AgentLoopWorker pid=8803) ERROR:2026-01-21 22:59:59,285:Error executing code: signal only works in main thread of the main interpreter

Root Cause: This error is caused by the use of Python's signal module in PythonCoderTool (e.g., signal.alarm(0)). Python's signal.signal() function can only be called in the main thread of the main interpreter, which leads to this error.

我们在进行RL训练时,出现如下报错:

(AgentLoopWorker pid=8803) ERROR:2026-01-21 22:59:59,285:Error executing code: signal only works in main thread of the main interpreter

【报错原因】因 PythonCoderTool 中使用了Python的signal模块(例如signal.alarm(0)),而Python的signal.signal() 函数只能在主线程的主解释器中调用。因此导致报错。

Activity

  1. IsaacGHX commented on Jan 22, 2026

    @IsaacGHX
    Collaborator

    Hi xixi!

    Many thanks for your raised bug.

    @Zhuofeng-Li Consider refine tool Python_Coder further.

    If there's any other issue found in our repo, please feel free to info us!

  2. Zhuofeng-Li commented on Jan 23, 2026

    @Zhuofeng-Li
    Collaborator

    No problem!

  3. IsaacGHX commented on Jan 23, 2026

    @IsaacGHX
    Collaborator

    Hi @zhangxixi551, We’ve pushed a new hotfix in #PR 31. It’s not yet validated on training runs. If you happen to test it and share your feedback, that would be greatly appreciated and should help us decide on merging.

  4. zhangxixi551 commented on Jan 26, 2026

    @zhangxixi551
    Author

    Hi @zhangxixi551, We’ve pushed a new hotfix in #PR 31. It’s not yet validated on training runs. If you happen to test it and share your feedback, that would be greatly appreciated and should help us decide on merging.

    I am very grateful for the author's reply and code modifications!

    However, after recent testing, I found that your defined
    @contextmanager def timeout(seconds): ...
    cannot effectively terminate Python code that has exceeded its time limit because:

    Exceptions thrown by threading.Timer cannot interrupt the running main thread code.

    Specifically:

    The Timer thread runs in the background: threading.Timer will execute raise_timeout() in another thread (Thread-1) after the time limit is exceeded.

    Exceptions cannot propagate across threads: A TimeoutException thrown in Thread-1 will not affect exec(execution_code) currently executing in the main thread.

    The main thread's exec() will continue to run until completion (even if the time limit has exceeded).

    非常感激作者的回信以及对代码的修改!
    不过我最近经过测试后发现,您定义的
    @contextmanager
    def timeout(seconds):
    ...
    无法有效终止已超出时间限制的python code,原因是:
    threading.Timer 抛出的异常不能中断正在运行的主线程代码。

    具体来说:
    Timer线程在后台运行:threading.Timer 会在超出时间限制后在另一个线程(Thread-1)中执行raise_timeout()
    异常无法跨线程传播:在Thread-1中抛出的TimeoutException不会影响主线程中正在执行的exec(execution_code)
    主线程的 exec() 会继续运行直到完成(即使已经超出时间限制)

  5. Zhuofeng-Li commented on Jan 27, 2026

    @Zhuofeng-Li
    Collaborator

    Thank you very much for the update! We really appreciate it.

    We are currently working on resolving the timeout termination issue related to the thread chaining. We’ll keep you posted as we make progress.

  6. zhangxixi551 commented on Jan 27, 2026

    @zhangxixi551
    Author

    Thank you very much for the update! We really appreciate it.

    We are currently working on resolving the timeout termination issue related to the thread chaining. We’ll keep you posted as we make progress.

    I am so grateful to receive your reply! I look forward to it!

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions