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: make the app launchable when nest_asyncio is applied #1783

Merged
merged 2 commits into from
Nov 18, 2023

Conversation

mikeldking
Copy link
Contributor

@mikeldking mikeldking commented Nov 18, 2023

resolves #1353

This resolves the issue that nest asyncio makes the application fail to launch. Many notebooks, including ones from llamaIndex, have nest_asyncio applied at the top. In these cases the server cannot crash. This makes it so that the server runs via the "asyncio" eventloop when it is applied.

import os
import phoenix as px
import logging
import nest_asyncio

nest_asyncio.apply()
logging.basicConfig(level=logging.INFO)
px.launch_app()
INFO:phoenix.session.session:Running Phoenix in a process
INFO:phoenix.services:command: [/Users/mikeldking/.virtualenvs/phoenix/bin/python](https://file+.vscode-resource.vscode-cdn.net/Users/mikeldking/.virtualenvs/phoenix/bin/python) main.py --export_path [/var/folders/1s/4vdv59n15b1ghg42frdd8f480000gn/T/tmp1z1xx6_c/exports](https://file+.vscode-resource.vscode-cdn.net/var/folders/1s/4vdv59n15b1ghg42frdd8f480000gn/T/tmp1z1xx6_c/exports) --host 127.0.0.1 --port 6006 --umap_params 0.0,30,500 datasets --primary phoenix_dataset_67bf7bad-1f57-4312-840a-2d32aa6b262a
🌍 To view the Phoenix app in your browser, visit http://127.0.0.1:6006/
📺 To view the Phoenix app in a notebook, run `px.active_session().view()`
📖 For more information on how to use Phoenix, check out https://docs.arize.com/phoenix

Copy link
Contributor

@RogerHYang RogerHYang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See alternate solution here.

@mikeldking
Copy link
Contributor Author

See alternate solution here.

Oh nice, yeah let's do that

@mikeldking
Copy link
Contributor Author

Though it seems like there is a performance hit

When you're writing production code, it is better to use uvloop than the built-in asyncio event loop. Uvloop is a fast, drop-in replacement for the built-in asyncio event loop of Python. It is written in Cython and built on top of libuv, which is a multi-platform support library with a focus on asynchronous I/O.

@RogerHYang
Copy link
Contributor

RogerHYang commented Nov 18, 2023

Though it seems like there is a performance hit

When you're writing production code, it is better to use uvloop than the built-in asyncio event loop. Uvloop is a fast, drop-in replacement for the built-in asyncio event loop of Python. It is written in Cython and built on top of libuv, which is a multi-platform support library with a focus on asynchronous I/O.

True, but the server is not handling (hundreds of) thousands of requests/s, so it's probably an acceptable trade-off.

@mikeldking mikeldking force-pushed the run-in-process-if-nestasyncio branch from 720cad3 to 07faec5 Compare November 18, 2023 22:42
Copy link
Contributor

@RogerHYang RogerHYang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

src/phoenix/server/thread_server.py Outdated Show resolved Hide resolved
@mikeldking mikeldking changed the title fix: automatically run in a process if nest_asyncio is applied fix: make the app launchable when nest_asyncio is applied Nov 18, 2023
@mikeldking mikeldking merged commit f9d5085 into main Nov 18, 2023
11 checks passed
@mikeldking mikeldking deleted the run-in-process-if-nestasyncio branch November 18, 2023 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[BUG] phoenix fails to launch when asyncio is nested
2 participants