mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 03:44:55 +00:00 
			
		
		
		
	asyncio doc: add an example to schedule a coroutine from a different thread
This commit is contained in:
		
							parent
							
								
									d8b24d756a
								
							
						
					
					
						commit
						5cb84ed5b1
					
				
					 1 changed files with 8 additions and 5 deletions
				
			
		| 
						 | 
					@ -13,12 +13,15 @@ Concurrency and multithreading
 | 
				
			||||||
------------------------------
 | 
					------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
An event loop runs in a thread and executes all callbacks and tasks in the same
 | 
					An event loop runs in a thread and executes all callbacks and tasks in the same
 | 
				
			||||||
thread.  If a callback should be scheduled from a different thread, the
 | 
					thread. While a task in running in the event loop, no other task is running in
 | 
				
			||||||
:meth:`BaseEventLoop.call_soon_threadsafe` method should be used.
 | 
					the same thread. But when the task uses ``yield from``, the task is suspended
 | 
				
			||||||
 | 
					and the event loop executes the next task.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
While a task in running in the event loop, no other task is running in the same
 | 
					To schedule a callback from a different thread, the
 | 
				
			||||||
thread. But when the task uses ``yield from``, the task is suspended and the
 | 
					:meth:`BaseEventLoop.call_soon_threadsafe` method should be used. Example to
 | 
				
			||||||
event loop executes the next task.
 | 
					schedule a coroutine from a different::
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    loop.call_soon_threadsafe(asyncio.async, coro_func())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
To handle signals and to execute subprocesses, the event loop must be run in
 | 
					To handle signals and to execute subprocesses, the event loop must be run in
 | 
				
			||||||
the main thread.
 | 
					the main thread.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue