5757//! #[pymodule]
5858//! mod my_module{
5959//! use super::*;
60- //!
60+ //!
6161//! #[pymodule_init]
6262//! fn init(_m: &Bound<'_, PyModule>) -> PyResult<()> {
6363//! pyo3_log::init();
6464//! Ok(())
6565//! }
66- //!
66+ //!
6767//! #[pyfunction]
6868//! fn log_something() {
6969//! info!("Something!");
108108//! # use pyo3_log::{Caching, Logger};
109109//! #
110110//! # fn main() -> PyResult<()> {
111- //! # Python::with_gil (|py| {
111+ //! # Python::attach (|py| {
112112//! let handle = Logger::new(py, Caching::LoggersAndLevels)?
113113//! .filter(LevelFilter::Trace)
114114//! .filter_target("my_module::verbose_submodule".to_owned(), LevelFilter::Warn)
171171//! fn dont_deadlock(py: Python<'_>) {
172172//! info!("This logs fine");
173173//!
174- //! py.allow_threads (|| {
174+ //! py.detach (|| {
175175//! let background_thread = thread::spawn(|| {
176176//! info!("This'll not deadlock");
177177//! });
@@ -242,7 +242,7 @@ pub enum Caching {
242242#[ derive( Debug ) ]
243243struct CacheEntry {
244244 filter : LevelFilter ,
245- logger : PyObject ,
245+ logger : Py < PyAny > ,
246246}
247247
248248impl CacheEntry {
@@ -430,7 +430,7 @@ impl Logger {
430430 py : Python < ' _ > ,
431431 record : & Record ,
432432 cache : & Option < Arc < CacheNode > > ,
433- ) -> PyResult < Option < PyObject > > {
433+ ) -> PyResult < Option < Py < PyAny > > > {
434434 let msg = format ! ( "{}" , record. args( ) ) ;
435435 let log_level = map_level ( record. level ( ) ) ;
436436 let target = record. target ( ) . replace ( "::" , "." ) ;
@@ -520,7 +520,7 @@ impl Logger {
520520
521521impl Default for Logger {
522522 fn default ( ) -> Self {
523- Python :: with_gil ( |py| {
523+ Python :: attach ( |py| {
524524 Self :: new ( py, Caching :: LoggersAndLevels ) . expect ( "Failed to initialize python logging" )
525525 } )
526526 }
@@ -537,7 +537,7 @@ impl Log for Logger {
537537 let cache = self . lookup ( record. target ( ) ) ;
538538
539539 if self . enabled_inner ( record. metadata ( ) , & cache) {
540- Python :: with_gil ( |py| {
540+ Python :: attach ( |py| {
541541 // If an exception were triggered before this attempt to log,
542542 // store it to the side for now and restore it afterwards.
543543 let maybe_existing_exception = PyErr :: take ( py) ;
0 commit comments