Skip to content

Conversation

@MasterofJOKers
Copy link
Contributor

We expose the functionality to run CliMenu in a background thread that the underlying prompt_toolkit library supports through a run_in_thread argument. This functionality can be necessary if we get called from a running event loop as the documentation of in_thread describes:

:param in_thread: When true, run the application in a background
	thread, and block the current thread until the application
	terminates. This is useful if we need to be sure the application
	won't use the current event loop (asyncio does not support nested
	event loops). A new event loop will be created in this background
	thread, and that loop will also be closed when the background
	thread terminates. When this is used, it's especially important to
	make sure that all asyncio background tasks are managed through
	`get_appp().create_background_task()`, so that unfinished tasks are
	properly cancelled before the event loop is closed. This is used
	for instance in ptpython.

We expose the functionality to run `CliMenu` in a background thread that
the underlying `prompt_toolkit` library supports through a
`run_in_thread` argument. This functionality can be necessary if we get
called from a running event loop as the documentation of `in_thread`
describes:

	:param in_thread: When true, run the application in a background
		thread, and block the current thread until the application
		terminates. This is useful if we need to be sure the application
		won't use the current event loop (asyncio does not support nested
		event loops). A new event loop will be created in this background
		thread, and that loop will also be closed when the background
		thread terminates. When this is used, it's especially important to
		make sure that all asyncio background tasks are managed through
		`get_appp().create_background_task()`, so that unfinished tasks are
		properly cancelled before the event loop is closed. This is used
		for instance in ptpython.
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.

1 participant