{"id":3233,"date":"2024-05-01T15:55:02","date_gmt":"2024-05-01T15:55:02","guid":{"rendered":"https:\/\/www.infobip.com\/developers\/?p=3233"},"modified":"2024-05-01T15:57:46","modified_gmt":"2024-05-01T15:57:46","slug":"dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management","status":"publish","type":"post","link":"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management","title":{"rendered":"Don&#8217;t try this in prod: adding text alerts to Python&#8217;s memory management"},"content":{"rendered":"\n<p>I love Python. It\u2019s a versatile, powerful language with a gentle learning curve, and you can do all sorts of cool things with it. However, it has some downsides, and one of them is that &#8211; as a language <a href=\"https:\/\/realpython.com\/python-memory-management\/\">without explicit memory management<\/a> &#8211; it can be hard to understand what\u2019s happening to objects in memory during runtime.<\/p>\n\n\n\n<p>Python has <a href=\"https:\/\/docs.python.org\/3\/library\/gc.html\">garbage collection<\/a>, which means that within a running Python program, every now and then the runtime will scan through every object in memory and determine whether or not it\u2019s still needed. If the garbage collector decides that the object is no longer necessary, it will remove it from memory. But this process is entirely abstracted from the programmer, and for those of us who want to know what\u2019s actually going on in our software, it can be frustrating.<\/p>\n\n\n\n<p>In this blog post, I\u2019m going to demonstrate an impractical idea for gaining a little visibility into your Python runtime\u2019s memory management: getting a text sent to your phone every time an object is removed from memory.<\/p>\n\n\n\n<p>In order to do this, I\u2019ll need a <a href=\"https:\/\/www.infobip.com\/signup\">free Infobip account<\/a> and the credentials that come along with it, and a terminal where I can run some Python code.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Setting up the Infobip SMS Channel<\/h1>\n\n\n\n<p>For the purposes of this blog post, I\u2019m simply going to create a single Python file, <code>garbage_texts.py<\/code>. For this to work, I need the <a href=\"https:\/\/github.com\/infobip-community\/infobip-api-python-sdk\/\">Infobip Python API SDK<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install infobip-api-python-sdk<\/code><\/pre>\n\n\n\n<p>Now, in my new <code>garbage_texts.py<\/code> file, I\u2019ll set up an Infobip SMS Channel using the credentials from my account. I can access these credentials either from my <a href=\"https:\/\/portal.infobip.com\/homepage\/\" target=\"_blank\" rel=\"noreferrer noopener\">Infobip account<\/a> or from the <a href=\"https:\/\/www.infobip.com\/docs\/api\" target=\"_blank\" rel=\"noreferrer noopener\">Infobip API landing page<\/a>, provided I have logged in.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from infobip_channels.sms.channel import SMSChannel\n\nchannel = SMSChannel.from_auth_params({\n&nbsp;&nbsp;&nbsp;&nbsp;\"base_url\": \"&lt;my_base_url&gt;\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"api_key\": \"&lt;my_api_key&gt;\"\n\n})<\/code><\/pre>\n\n\n\n<p>From now on, I can use this channel to send texts to my own phone number (registered during Infobip account creation) with the <code>send_sms_message<\/code> method.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Writing a class to send texts on deletion<\/h1>\n\n\n\n<p>Next, I\u2019ll define a class that will text me whenever an instance of it is removed from memory. This is done by overriding the class\u2019s <a href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__del__\"><code>__del__<\/code> method<\/a>, the magic method that\u2019s called by the Python runtime when it removes an object. This method is also called the finalizer.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class TextingClass:\n\tdef __init__(self, name: str):\n\t\t# This class takes a name parameter so we can distinguish instances\n\t\tself.name = name\n\n\tdef __del__(self):\n\t\t# Here\u2019s where the object sends a text using the Infobip SMSChannel\n\t\tchannel.send_sms_message({\"messages\":&#91;{\n\t \t\t\"destinations\": &#91;{\"to\": \"&lt;my_phone_number>\"}],\n\t\t\t\"from\": \"Python Runtime\",\n\t\t\t\"text\": f\"The object with name {self.name} is being removed from memory!\"\n\t\t}]})<\/code><\/pre>\n\n\n\n<p>This class uses the Infobip SMS Channel to report when its instances are being removed from memory, so I can see what\u2019s going on in my code.<\/p>\n\n\n\n<p>To check that it works, I\u2019ll add a script to&nbsp; <code>garbage_texts.py<\/code> at the end of the file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if __name__ == \u201c__main__\u201d:\n\tthing_one = TextingClass(\u201cThing One\u201d)\n\tdel thing_one\n\n\timport time\n\ttime.sleep(500)<\/code><\/pre>\n\n\n\n<p>All this script does is create an instance of my <code>TextingClass<\/code> and then delete its namespace reference, <code>thing_one<\/code>. That causes its <a href=\"https:\/\/devguide.python.org\/internals\/garbage-collector\/index.html\">reference count<\/a> to fall to zero, and that instance is removed from memory. Then the script <a href=\"https:\/\/docs.python.org\/3\/library\/time.html#time.sleep\">waits to exit for 500 seconds<\/a>, so that I can be sure that the text happened on the <code>del<\/code> line and not because the runtime exited when the script ends.<\/p>\n\n\n\n<p>To run this code, all I need to do is the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python garbage_texts.py<\/code><\/pre>\n\n\n\n<p>Technically speaking, in this example the garbage collector wasn\u2019t used at all. The garbage collector only comes into play when cyclic isolates are created, a situation in which objects contain references to each other but have no references from the namespace. I can easily set up a cyclic isolate with two elements in my script:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if __name__ == \u201c__main__\u201d:\n\tthing_one = TextingClass(\u201cThing One\u201d)\n\tdel thing_one\n\t\n\tthing_two = TextingClass(\u201cThing Two\u201d)\n\tthing_three = TextingClass(\u201cThing Three\u201d)\n\n\t# create cyclic references\n\tthing_two.reference = thing_three\n\tthing_three.reference = thing_two\n\n\t# isolate the cyclic reference objects from the namespace\n\tdel thing_two\n\tdel thing_tree \n\n\timport time\n\ttime.sleep(500)<\/code><\/pre>\n\n\n\n<p>If I run this code as is, I won\u2019t get texts about Thing Two and Three being removed from memory until the script ends in 500 seconds. To remove them earlier, I need to run the garbage collector manually before the <code>sleep<\/code> call :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import gc\ngc.collect()<\/code><\/pre>\n\n\n\n<p>In general, the garbage collector runs on its own automatically, and you can <a href=\"https:\/\/docs.python.org\/3\/library\/gc.html#gc.set_threshold\">define how often you want that to happen<\/a> if the default behavior isn\u2019t right for your use case. In this case, I want to force it to run, which is what that code does.<\/p>\n\n\n\n<p>Now, when I run my script, I\u2019ll see texts for all three objects before the script exits.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Using decorators to send ALL the texts<\/h1>\n\n\n\n<p>So, I\u2019ve shown how to write a single custom class that\u2019ll send texts when instances of it are removed from memory. But what if I wanted all my custom Python objects to do this? That\u2019d be a lot of repeated code, and we all know <a href=\"https:\/\/en.wikipedia.org\/wiki\/Don%27t_repeat_yourself\">the rule about repeating yourself<\/a>. Fortunately, I can write a <a href=\"https:\/\/realpython.com\/primer-on-python-decorators\/\">decorator<\/a> that will amend the <code>__del__<\/code> method of any class to send a text when it\u2019s called.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def text_on_delete(cls):\n\t# Get the original finalizer method\n\tbase_del = getattr(cls, '__del__\u2019')\n\n\t# Define a new one that\u2019ll send texts\n\tdef del_with_text(self):\n\t\tchannel.send_sms_message({ \"messages\": &#91;{\n \t\t\"destinations\": &#91;{\n\t\t\t\t\"to\": \"&lt;my_phone_number>\"\n\t\t\t}],\n\t\t\t\"from\": \"Python Runtime\",\n\t\t\t\"text\": f\"The object {self} is being removed from memory!\"\n\t\t}]})\n\t\t# Call the original finalizer\n\t\tbase_del(self)\n\n\t# Make sure the class uses our new finalizer\n\tsetattr(cls, '__del__', del_with_text)\n\treturn cls<\/code><\/pre>\n\n\n\n<p>Using this decorator, my <code>TextingClass<\/code> can look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@text_on_delete\nclass TextingClass:\n\tdef __init__(self, name: str):\n\t\t# This class takes a name parameter so we can distinguish instances\n\t\tself.name = name<\/code><\/pre>\n\n\n\n<p>A lot cleaner!<\/p>\n\n\n\n<p>If you actually used this in a production system, you\u2019d quickly get overwhelmed with text messages. However, you could modify this code to only send a text every 1000 objects, or to <a href=\"https:\/\/www.infobip.com\/developers\/blog\/how-to-send-an-email-with-python-and-infobip\">send an email instead<\/a>. More practically, knowing how to hook into Python\u2019s built-in magic methods and use decorators to achieve the behavior you want comes in handy all the time. This is a fun way to gain some visibility into what\u2019s actually happening when you do so!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I love Python. It\u2019s a versatile, powerful language with [&hellip;]<\/p>\n","protected":false},"author":53,"featured_media":3111,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[28,255],"tags":[256],"coauthors":[285],"class_list":["post-3233","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-post","category-infobip-products","tag-programming"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Don&#039;t try this in prod: adding text alerts to Python&#039;s memory management - Infobip Developers Hub<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Don&#039;t try this in prod: adding text alerts to Python&#039;s memory management - Infobip Developers Hub\" \/>\n<meta property=\"og:description\" content=\"I love Python. It\u2019s a versatile, powerful language with [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management\" \/>\n<meta property=\"og:site_name\" content=\"Infobip Developers Hub\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/infobip\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-05-01T15:55:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-01T15:57:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"694\" \/>\n\t<meta property=\"og:image:height\" content=\"451\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Eli Holderness\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@InfobipDev\" \/>\n<meta name=\"twitter:site\" content=\"@InfobipDev\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Eli Holderness\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management\"},\"author\":{\"name\":\"Eli Holderness\",\"@id\":\"https:\/\/www.infobip.com\/developers\/#\/schema\/person\/2d3f818bd258646bc997a3ec04146bbd\"},\"headline\":\"Don&#8217;t try this in prod: adding text alerts to Python&#8217;s memory management\",\"datePublished\":\"2024-05-01T15:55:02+00:00\",\"dateModified\":\"2024-05-01T15:57:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management\"},\"wordCount\":839,\"publisher\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png\",\"keywords\":[\"programming\"],\"articleSection\":[\"Blog Post\",\"Infobip Products\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management\",\"url\":\"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management\",\"name\":\"Don't try this in prod: adding text alerts to Python's memory management - Infobip Developers Hub\",\"isPartOf\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png\",\"datePublished\":\"2024-05-01T15:55:02+00:00\",\"dateModified\":\"2024-05-01T15:57:46+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management#primaryimage\",\"url\":\"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png\",\"contentUrl\":\"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png\",\"width\":694,\"height\":451,\"caption\":\"A blog cover image showing the Python logo on the left and the Infobip logo on the right.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.infobip.com\/developers\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Don&#8217;t try this in prod: adding text alerts to Python&#8217;s memory management\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.infobip.com\/developers\/#website\",\"url\":\"https:\/\/www.infobip.com\/developers\/\",\"name\":\"Infobip Developers Hub\",\"description\":\"Build meaningful customer relationships across any channel\",\"publisher\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.infobip.com\/developers\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.infobip.com\/developers\/#organization\",\"name\":\"Infobip Developers Hub\",\"url\":\"https:\/\/www.infobip.com\/developers\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.infobip.com\/developers\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2023\/03\/Infobip_logo_favicon.png\",\"contentUrl\":\"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2023\/03\/Infobip_logo_favicon.png\",\"width\":696,\"height\":696,\"caption\":\"Infobip Developers Hub\"},\"image\":{\"@id\":\"https:\/\/www.infobip.com\/developers\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/infobip\/\",\"https:\/\/x.com\/InfobipDev\",\"https:\/\/www.youtube.com\/channel\/UCUPSTy53VecI5GIir3J3ZbQ\",\"https:\/\/github.com\/infobip-community\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.infobip.com\/developers\/#\/schema\/person\/2d3f818bd258646bc997a3ec04146bbd\",\"name\":\"Eli Holderness\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.infobip.com\/developers\/#\/schema\/person\/image\/e3fd4a8aa6b78952d057f724bcf1dff0\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2261319993db9030e1328c712ee20e4aaedf2c9cb8e4379ae8af57f2c877d5f4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2261319993db9030e1328c712ee20e4aaedf2c9cb8e4379ae8af57f2c877d5f4?s=96&d=mm&r=g\",\"caption\":\"Eli Holderness\"},\"description\":\"Developer advocate, conference speaker &amp; professional nerd. Likes maths, knitting, and cats.\",\"url\":\"https:\/\/www.infobip.com\/developers\/blog\/author\/eli\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Don't try this in prod: adding text alerts to Python's memory management - Infobip Developers Hub","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management","og_locale":"en_US","og_type":"article","og_title":"Don't try this in prod: adding text alerts to Python's memory management - Infobip Developers Hub","og_description":"I love Python. It\u2019s a versatile, powerful language with [&hellip;]","og_url":"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management","og_site_name":"Infobip Developers Hub","article_publisher":"https:\/\/www.facebook.com\/infobip\/","article_published_time":"2024-05-01T15:55:02+00:00","article_modified_time":"2024-05-01T15:57:46+00:00","og_image":[{"width":694,"height":451,"url":"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png","type":"image\/png"}],"author":"Eli Holderness","twitter_card":"summary_large_image","twitter_creator":"@InfobipDev","twitter_site":"@InfobipDev","twitter_misc":{"Written by":"Eli Holderness","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management#article","isPartOf":{"@id":"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management"},"author":{"name":"Eli Holderness","@id":"https:\/\/www.infobip.com\/developers\/#\/schema\/person\/2d3f818bd258646bc997a3ec04146bbd"},"headline":"Don&#8217;t try this in prod: adding text alerts to Python&#8217;s memory management","datePublished":"2024-05-01T15:55:02+00:00","dateModified":"2024-05-01T15:57:46+00:00","mainEntityOfPage":{"@id":"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management"},"wordCount":839,"publisher":{"@id":"https:\/\/www.infobip.com\/developers\/#organization"},"image":{"@id":"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management#primaryimage"},"thumbnailUrl":"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png","keywords":["programming"],"articleSection":["Blog Post","Infobip Products"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management","url":"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management","name":"Don't try this in prod: adding text alerts to Python's memory management - Infobip Developers Hub","isPartOf":{"@id":"https:\/\/www.infobip.com\/developers\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management#primaryimage"},"image":{"@id":"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management#primaryimage"},"thumbnailUrl":"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png","datePublished":"2024-05-01T15:55:02+00:00","dateModified":"2024-05-01T15:57:46+00:00","breadcrumb":{"@id":"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management#primaryimage","url":"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png","contentUrl":"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2024\/02\/flask2.png","width":694,"height":451,"caption":"A blog cover image showing the Python logo on the left and the Infobip logo on the right."},{"@type":"BreadcrumbList","@id":"https:\/\/www.infobip.com\/developers\/blog\/dont-try-this-in-prod-adding-text-alerts-to-pythons-memory-management#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.infobip.com\/developers\/"},{"@type":"ListItem","position":2,"name":"Don&#8217;t try this in prod: adding text alerts to Python&#8217;s memory management"}]},{"@type":"WebSite","@id":"https:\/\/www.infobip.com\/developers\/#website","url":"https:\/\/www.infobip.com\/developers\/","name":"Infobip Developers Hub","description":"Build meaningful customer relationships across any channel","publisher":{"@id":"https:\/\/www.infobip.com\/developers\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.infobip.com\/developers\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.infobip.com\/developers\/#organization","name":"Infobip Developers Hub","url":"https:\/\/www.infobip.com\/developers\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.infobip.com\/developers\/#\/schema\/logo\/image\/","url":"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2023\/03\/Infobip_logo_favicon.png","contentUrl":"https:\/\/www.infobip.com\/developers\/wp-content\/uploads\/2023\/03\/Infobip_logo_favicon.png","width":696,"height":696,"caption":"Infobip Developers Hub"},"image":{"@id":"https:\/\/www.infobip.com\/developers\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/infobip\/","https:\/\/x.com\/InfobipDev","https:\/\/www.youtube.com\/channel\/UCUPSTy53VecI5GIir3J3ZbQ","https:\/\/github.com\/infobip-community"]},{"@type":"Person","@id":"https:\/\/www.infobip.com\/developers\/#\/schema\/person\/2d3f818bd258646bc997a3ec04146bbd","name":"Eli Holderness","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.infobip.com\/developers\/#\/schema\/person\/image\/e3fd4a8aa6b78952d057f724bcf1dff0","url":"https:\/\/secure.gravatar.com\/avatar\/2261319993db9030e1328c712ee20e4aaedf2c9cb8e4379ae8af57f2c877d5f4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2261319993db9030e1328c712ee20e4aaedf2c9cb8e4379ae8af57f2c877d5f4?s=96&d=mm&r=g","caption":"Eli Holderness"},"description":"Developer advocate, conference speaker &amp; professional nerd. Likes maths, knitting, and cats.","url":"https:\/\/www.infobip.com\/developers\/blog\/author\/eli"}]}},"_links":{"self":[{"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/posts\/3233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/users\/53"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/comments?post=3233"}],"version-history":[{"count":6,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/posts\/3233\/revisions"}],"predecessor-version":[{"id":3240,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/posts\/3233\/revisions\/3240"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/media\/3111"}],"wp:attachment":[{"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/media?parent=3233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/categories?post=3233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/tags?post=3233"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.infobip.com\/developers\/wp-json\/wp\/v2\/coauthors?post=3233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}