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

fix: threading applications using ape #1941

Merged
merged 3 commits into from
Mar 6, 2024

Conversation

Gonmeso
Copy link
Contributor

@Gonmeso Gonmeso commented Feb 28, 2024

What I did

Add signal handling for applications that use Ape using threads, this could be APIs, streamlit applications and prefect flows

fixes: #1164

How I did it

Checked if we are running in the main thread or not, if we are signaling is applied as usual, otherwise it won't be applied. This means more traceback for threaded applications but it will work.

How to verify it

Previously ape fails at import time due to signalling failing to be achieved on a child thread.

Running the following script without the change will result in an error ValueError: signal only works in main thread of the main interpreter :

import threading

def import_ape():
    import ape

thread = threading.Thread(target=import_ape)

thread.start()
thread.join()

print("Done")

Once the change is applied ape is successfully loaded

Checklist

  • All changes are completed
  • New test cases have been added
  • Documentation has been updated

@Gonmeso Gonmeso changed the title Fix threading applications using ape fix: threading applications using ape Feb 28, 2024
@antazoey antazoey enabled auto-merge (squash) March 6, 2024 19:54
@antazoey antazoey merged commit 635bef5 into ApeWorX:main Mar 6, 2024
15 checks passed
@Gonmeso Gonmeso deleted the fix/threading-signal-error branch March 11, 2024 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to use ape inside of streamlit app
2 participants