Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/emilyhunt/smartmultiprocessing. Memory-managed parallel computing for medium-sized computational tasks.
Something went wrong. Try again.
37 kB · 1076 lines
HTML
at gh-pages
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
<!doctype html><html lang="en" class="no-js"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="description" content="A drop-in replacement for Python's `multiprocessing` library with many extra features, including: memory management, smart task scheduling, a pause button, a GUI, and more."> <meta name="author" content="Emily Hunt"> <link rel="canonical" href="https://smartmultiprocessing.org/api/smartprocess/"> <link rel="prev" href="../.."> <link rel="icon" href="../../_static/favicon.png"> <meta name="generator" content="mkdocs-1.5.3, mkdocs-material-9.5.17"> <title>SmartProcess - SmartMultiprocessing</title> <link rel="stylesheet" href="../../assets/stylesheets/main.bcfcd587.min.css"> <link rel="stylesheet" href="../../assets/stylesheets/palette.06af60db.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback"> <style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style> <link rel="stylesheet" href="../../assets/_mkdocstrings.css"> <script>__md_scope=new URL("../..",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
</head> <body dir="ltr" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="amber"> <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off"> <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off"> <label class="md-overlay" for="__drawer"></label> <div data-md-component="skip"> <a href="#smartprocess" class="md-skip"> Skip to content </a> </div> <div data-md-component="announce"> </div>
<header class="md-header md-header--shadow" data-md-component="header"> <nav class="md-header__inner md-grid" aria-label="Header"> <a href="../.." title="SmartMultiprocessing" class="md-header__button md-logo" aria-label="SmartMultiprocessing" data-md-component="logo"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 2a7 7 0 0 1 7 7c0 2.38-1.19 4.47-3 5.74V17a1 1 0 0 1-1 1H9a1 1 0 0 1-1-1v-2.26C6.19 13.47 5 11.38 5 9a7 7 0 0 1 7-7M9 21v-1h6v1a1 1 0 0 1-1 1h-4a1 1 0 0 1-1-1m3-17a5 5 0 0 0-5 5c0 2.05 1.23 3.81 3 4.58V16h4v-2.42c1.77-.77 3-2.53 3-4.58a5 5 0 0 0-5-5Z"/></svg>
</a> <label class="md-header__button md-icon" for="__drawer"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg> </label> <div class="md-header__title" data-md-component="header-title"> <div class="md-header__ellipsis"> <div class="md-header__topic"> <span class="md-ellipsis"> SmartMultiprocessing </span> </div> <div class="md-header__topic" data-md-component="header-topic"> <span class="md-ellipsis"> SmartProcess </span> </div> </div> </div> <form class="md-header__option" data-md-component="palette"> <input class="md-option" data-md-color-media="" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="amber" aria-label="Switch to dark mode" type="radio" name="__palette" id="__palette_0"> <label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_1" hidden> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="m17.75 4.09-2.53 1.94.91 3.06-2.63-1.81-2.63 1.81.91-3.06-2.53-1.94L12.44 4l1.06-3 1.06 3 3.19.09m3.5 6.91-1.64 1.25.59 1.98-1.7-1.17-1.7 1.17.59-1.98L15.75 11l2.06-.05L18.5 9l.69 1.95 2.06.05m-2.28 4.95c.83-.08 1.72 1.1 1.19 1.85-.32.45-.66.87-1.08 1.27C15.17 23 8.84 23 4.94 19.07c-3.91-3.9-3.91-10.24 0-14.14.4-.4.82-.76 1.27-1.08.75-.53 1.93.36 1.85 1.19-.27 2.86.69 5.83 2.89 8.02a9.96 9.96 0 0 0 8.02 2.89m-1.64 2.02a12.08 12.08 0 0 1-7.8-3.47c-2.17-2.19-3.33-5-3.49-7.82-2.81 3.14-2.7 7.96.31 10.98 3.02 3.01 7.84 3.12 10.98.31Z"/></svg> </label> <input class="md-option" data-md-color-media="" data-md-color-scheme="slate" data-md-color-primary="indigo" data-md-color-accent="amber" aria-label="Switch to light mode" type="radio" name="__palette" id="__palette_1"> <label class="md-header__button md-icon" title="Switch to light mode" for="__palette_0" hidden> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 7a5 5 0 0 1 5 5 5 5 0 0 1-5 5 5 5 0 0 1-5-5 5 5 0 0 1 5-5m0 2a3 3 0 0 0-3 3 3 3 0 0 0 3 3 3 3 0 0 0 3-3 3 3 0 0 0-3-3m0-7 2.39 3.42C13.65 5.15 12.84 5 12 5c-.84 0-1.65.15-2.39.42L12 2M3.34 7l4.16-.35A7.2 7.2 0 0 0 5.94 8.5c-.44.74-.69 1.5-.83 2.29L3.34 7m.02 10 1.76-3.77a7.131 7.131 0 0 0 2.38 4.14L3.36 17M20.65 7l-1.77 3.79a7.023 7.023 0 0 0-2.38-4.15l4.15.36m-.01 10-4.14.36c.59-.51 1.12-1.14 1.54-1.86.42-.73.69-1.5.83-2.29L20.64 17M12 22l-2.41-3.44c.74.27 1.55.44 2.41.44.82 0 1.63-.17 2.37-.44L12 22Z"/></svg> </label> </form> <script>var media,input,key,value,palette=__md_get("__palette");if(palette&&palette.color){"(prefers-color-scheme)"===palette.color.media&&(media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']"),palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent"));for([key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script> <label class="md-header__button md-icon" for="__search"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg> </label> <div class="md-search" data-md-component="search" role="dialog"> <label class="md-search__overlay" for="__search"></label> <div class="md-search__inner" role="search"> <form class="md-search__form" name="search"> <input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required> <label class="md-search__icon md-icon" for="__search"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg> </label> <nav class="md-search__options" aria-label="Search"> <a href="javascript:void(0)" class="md-search__icon md-icon" title="Share" aria-label="Share" data-clipboard data-clipboard-text="" data-md-component="search-share" tabindex="-1"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7 0-.24-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9a3 3 0 0 0-3 3 3 3 0 0 0 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.15c-.05.21-.08.43-.08.66 0 1.61 1.31 2.91 2.92 2.91 1.61 0 2.92-1.3 2.92-2.91A2.92 2.92 0 0 0 18 16.08Z"/></svg> </a> <button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"/></svg> </button> </nav> <div class="md-search__suggest" data-md-component="search-suggest"></div> </form> <div class="md-search__output"> <div class="md-search__scrollwrap" data-md-scrollfix> <div class="md-search-result" data-md-component="search-result"> <div class="md-search-result__meta"> Initializing search </div> <ol class="md-search-result__list" role="presentation"></ol> </div> </div> </div> </div></div> <div class="md-header__source"> <a href="https://github.com/emilyhunt/smartmultiprocessing" title="Go to repository" class="md-source" data-md-component="source"> <div class="md-source__icon md-icon"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><!--! Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/></svg> </div> <div class="md-source__repository"> smartmultiprocessing </div></a> </div> </nav> </header> <div class="md-container" data-md-component="container"> <main class="md-main" data-md-component="main"> <div class="md-main__inner md-grid"> <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" > <div class="md-sidebar__scrollwrap"> <div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary md-nav--integrated" aria-label="Navigation" data-md-level="0"> <label class="md-nav__title" for="__drawer"> <a href="../.." title="SmartMultiprocessing" class="md-nav__button md-logo" aria-label="SmartMultiprocessing" data-md-component="logo"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 2a7 7 0 0 1 7 7c0 2.38-1.19 4.47-3 5.74V17a1 1 0 0 1-1 1H9a1 1 0 0 1-1-1v-2.26C6.19 13.47 5 11.38 5 9a7 7 0 0 1 7-7M9 21v-1h6v1a1 1 0 0 1-1 1h-4a1 1 0 0 1-1-1m3-17a5 5 0 0 0-5 5c0 2.05 1.23 3.81 3 4.58V16h4v-2.42c1.77-.77 3-2.53 3-4.58a5 5 0 0 0-5-5Z"/></svg>
</a> SmartMultiprocessing </label> <div class="md-nav__source"> <a href="https://github.com/emilyhunt/smartmultiprocessing" title="Go to repository" class="md-source" data-md-component="source"> <div class="md-source__icon md-icon"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><!--! Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/></svg> </div> <div class="md-source__repository"> smartmultiprocessing </div></a> </div> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="../.." class="md-nav__link"> <span class="md-ellipsis"> SmartMultiprocessing is in development! </span>
</a> </li>
<li class="md-nav__item md-nav__item--active md-nav__item--section md-nav__item--nested"> <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2" checked> <label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex=""> <span class="md-ellipsis"> Api </span>
<span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_2_label" aria-expanded="true"> <label class="md-nav__title" for="__nav_2"> <span class="md-nav__icon md-icon"></span> Api </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item md-nav__item--active"> <input class="md-nav__toggle md-toggle" type="checkbox" id="__toc"> <label class="md-nav__link md-nav__link--active" for="__toc"> <span class="md-ellipsis"> SmartProcess </span>
<span class="md-nav__icon md-icon"></span> </label> <a href="./" class="md-nav__link md-nav__link--active"> <span class="md-ellipsis"> SmartProcess </span>
</a>
<nav class="md-nav md-nav--secondary" aria-label="Table of contents"> <label class="md-nav__title" for="__toc"> <span class="md-nav__icon md-icon"></span> Table of contents </label> <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix> <li class="md-nav__item"> <a href="#smartmultiprocessing.SmartProcess" class="md-nav__link"> <span class="md-ellipsis"> SmartProcess </span> </a> </li> <li class="md-nav__item"> <a href="#smartmultiprocessing.SmartProcess.__init__" class="md-nav__link"> <span class="md-ellipsis"> __init__ </span> </a> </li> <li class="md-nav__item"> <a href="#smartmultiprocessing.SmartProcess.get_children" class="md-nav__link"> <span class="md-ellipsis"> get_children </span> </a> </li> <li class="md-nav__item"> <a href="#smartmultiprocessing.SmartProcess.memory_usage" class="md-nav__link"> <span class="md-ellipsis"> memory_usage </span> </a> </li> <li class="md-nav__item"> <a href="#smartmultiprocessing.SmartProcess.cpu_usage" class="md-nav__link"> <span class="md-ellipsis"> cpu_usage </span> </a> </li> <li class="md-nav__item"> <a href="#smartmultiprocessing.SmartProcess.resource_usage" class="md-nav__link"> <span class="md-ellipsis"> resource_usage </span> </a> </li> <li class="md-nav__item"> <a href="#smartmultiprocessing.SmartProcess.get_result" class="md-nav__link"> <span class="md-ellipsis"> get_result </span> </a> </li> <li class="md-nav__item"> <a href="#smartmultiprocessing.SmartProcess.get_exitcode" class="md-nav__link"> <span class="md-ellipsis"> get_exitcode </span> </a> </li> <li class="md-nav__item"> <a href="#smartmultiprocessing.SmartProcess.run" class="md-nav__link"> <span class="md-ellipsis"> run </span> </a> </li> <li class="md-nav__item"> <a href="#smartmultiprocessing.SmartProcess.start" class="md-nav__link"> <span class="md-ellipsis"> start </span> </a> </li> <li class="md-nav__item"> <a href="#smartmultiprocessing.SmartProcess.join" class="md-nav__link"> <span class="md-ellipsis"> join </span> </a> </li> <li class="md-nav__item"> <a href="#smartmultiprocessing.SmartProcess.is_alive" class="md-nav__link"> <span class="md-ellipsis"> is_alive </span> </a> </li> <li class="md-nav__item"> <a href="#smartmultiprocessing.SmartProcess.is_finished" class="md-nav__link"> <span class="md-ellipsis"> is_finished </span> </a> </li> <li class="md-nav__item"> <a href="#smartmultiprocessing.SmartProcess.terminate" class="md-nav__link"> <span class="md-ellipsis"> terminate </span> </a> </li> <li class="md-nav__item"> <a href="#smartmultiprocessing.SmartProcess.kill" class="md-nav__link"> <span class="md-ellipsis"> kill </span> </a> </li> <li class="md-nav__item"> <a href="#smartmultiprocessing.SmartProcess.close" class="md-nav__link"> <span class="md-ellipsis"> close </span> </a> </li> </ul> </nav> </li>
</ul> </nav> </li>
</ul></nav> </div> </div> </div> <div class="md-content" data-md-component="content"> <article class="md-content__inner md-typeset">
<h1 id="smartprocess">SmartProcess<a class="headerlink" href="#smartprocess" title="Permanent link">¤</a></h1>
<div class="doc doc-object doc-class">
<a id="smartmultiprocessing.SmartProcess"></a> <div class="doc doc-contents first">
<p>Extension to <code>multiprocessing.Process</code> with multiple memory-managementoptions, the ability to return results from processes, and more.</p><p>This is a relatively low-level part of SmartMultiprocessing. Average users areprobably more interested in more abstract parts of this library, like <code>SmartPool</code> and <code>SmartQueue</code>, which can initialise as many <code>SmartProcess</code>es as you'dlike and include GUI options.</p><p>The API of <code>SmartProcess</code> matches that of <code>multiprocessing.Process</code>, except withsome notable additions like:</p><p><code>SmartProcess.resource_usage()</code> - get the process' current CPU and memory usage.</p><p><code>SmartProcess.is_finished()</code> - boolean for if process is done.</p><p><code>SmartProcess.get_result()</code> - get the result from <code>target</code>, if process finished.</p><p><code>SmartProcess.get_children()</code> - get all child processes of this process.</p>
<div class="doc doc-children">
<div class="doc doc-object doc-function">
<h2 id="smartmultiprocessing.SmartProcess.__init__" class="doc doc-heading"> <code class="highlight language-python"><span class="fm">__init__</span><span class="p">(</span><span class="n">group</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">(),</span> <span class="n">kwargs</span><span class="o">=</span><span class="p">{},</span> <span class="n">daemon</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">fetch_result</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span></code>
<a href="#smartmultiprocessing.SmartProcess.__init__" class="headerlink" title="Permanent link">¤</a></h2>
<div class="doc doc-contents "> <p>Create a new SmartProcess object.</p>
<p><strong>Parameters:</strong></p> <table> <thead> <tr> <th>Name</th> <th>Type</th> <th>Description</th> <th>Default</th> </tr> </thead> <tbody> <tr> <td><code>group</code></td> <td> <code>None</code> </td> <td> <div class="doc-md-description"> <p>Argument that must always be None. It exists for compatibility with thethreading.Thread API.</p> </div> </td> <td> <code>None</code> </td> </tr> <tr> <td><code>target</code></td> <td> <code><span title="typing.Callable">Callable</span></code> </td> <td> <div class="doc-md-description"> <p>Target function to run on.</p> </div> </td> <td> <code>None</code> </td> </tr> <tr> <td><code>name</code></td> <td> <code>str</code> </td> <td> <div class="doc-md-description"> <p>Name of process to pass to multiprocessing.Process.</p> </div> </td> <td> <code>None</code> </td> </tr> <tr> <td><code>args</code></td> <td> <code><span title="typing.Iterable">Iterable</span>[<span title="typing.Any">Any</span>]</code> </td> <td> <div class="doc-md-description"> <p>Arguments to pass to <code>target</code>.</p> </div> </td> <td> <code>()</code> </td> </tr> <tr> <td><code>kwargs</code></td> <td> <code>Mappable[str, <span title="typing.Any">Any</span>]</code> </td> <td> <div class="doc-md-description"> <p>Keyword arguments to pass to <code>target</code>.</p> </div> </td> <td> <code>{}</code> </td> </tr> <tr> <td><code>daemon</code></td> <td> <code>None or bool</code> </td> <td> <div class="doc-md-description"> <p>Whether or not to run as a daemon (background process). Passed tomultiprocessing.Process. TODO: not sure if this can actually be supported...</p> </div> </td> <td> <code>None</code> </td> </tr> <tr> <td><code>fetch_result</code></td> <td> <code>bool</code> </td> <td> <div class="doc-md-description"> <p>Whether or not to try and fetch a result in-memory for <code>target</code>. <code>target</code>must return a value for this to be used.</p> </div> </td> <td> <code>False</code> </td> </tr> </tbody> </table>
<details class="note" open> <summary>Notes</summary> <p>CPU and memory usage tracking is done using <code>psutil</code>. Support on systems thataren't Linux, Mac, or Windows may be limited.</p></details>
<p><strong>Examples:</strong></p> <p>Start a process that prints to the console in the background:</p> <div class="highlight"><pre><span></span><code><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">smartmultiprocessing</span><span class="o">.</span><span class="n">SmartProcess</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="k">lambda</span><span class="p">:</span> <span class="nb">print</span><span class="p">(</span><span class="s2">"Hello World"</span><span class="p">))</span><span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">start</span><span class="p">()</span><span class="go">Hello World</span></code></pre></div> <p>We can check if the process is finished:</p> <div class="highlight"><pre><span></span><code><span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">is_finished</span><span class="p">()</span><span class="go">True</span></code></pre></div> <p>or get its exitcode:</p> <div class="highlight"><pre><span></span><code><span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">get_exitcode</span><span class="p">()</span><span class="go">0</span></code></pre></div>
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="smartmultiprocessing.SmartProcess.get_children" class="doc doc-heading"> <code class="highlight language-python"><span class="n">get_children</span><span class="p">(</span><span class="n">recursive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span></code>
<a href="#smartmultiprocessing.SmartProcess.get_children" class="headerlink" title="Permanent link">¤</a></h2>
<div class="doc doc-contents "> <p>Gets the children of the process. TODO: document params</p>
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="smartmultiprocessing.SmartProcess.memory_usage" class="doc doc-heading"> <code class="highlight language-python"><span class="n">memory_usage</span><span class="p">(</span><span class="n">children</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span></code>
<a href="#smartmultiprocessing.SmartProcess.memory_usage" class="headerlink" title="Permanent link">¤</a></h2>
<div class="doc doc-contents "> <p>Returns current memory usage of the process.. TODO: document params</p>
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="smartmultiprocessing.SmartProcess.cpu_usage" class="doc doc-heading"> <code class="highlight language-python"><span class="n">cpu_usage</span><span class="p">(</span><span class="n">interval</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">children</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span></code>
<a href="#smartmultiprocessing.SmartProcess.cpu_usage" class="headerlink" title="Permanent link">¤</a></h2>
<div class="doc doc-contents "> <p>Returns current CPU usage of the process.. TODO: document params</p>
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="smartmultiprocessing.SmartProcess.resource_usage" class="doc doc-heading"> <code class="highlight language-python"><span class="n">resource_usage</span><span class="p">(</span><span class="n">interval</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">children</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span></code>
<a href="#smartmultiprocessing.SmartProcess.resource_usage" class="headerlink" title="Permanent link">¤</a></h2>
<div class="doc doc-contents ">
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="smartmultiprocessing.SmartProcess.get_result" class="doc doc-heading"> <code class="highlight language-python"><span class="n">get_result</span><span class="p">(</span><span class="n">join</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pipe_timeout</span><span class="o">=</span><span class="mf">1.0</span><span class="p">)</span></code>
<a href="#smartmultiprocessing.SmartProcess.get_result" class="headerlink" title="Permanent link">¤</a></h2>
<div class="doc doc-contents "> <p>Attempts to fetch a result for the process. TODO: document params</p>
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="smartmultiprocessing.SmartProcess.get_exitcode" class="doc doc-heading"> <code class="highlight language-python"><span class="n">get_exitcode</span><span class="p">()</span></code>
<a href="#smartmultiprocessing.SmartProcess.get_exitcode" class="headerlink" title="Permanent link">¤</a></h2>
<div class="doc doc-contents "> <p>Returns the exitcode of the process, which is only set if it has finished.</p>
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="smartmultiprocessing.SmartProcess.run" class="doc doc-heading"> <code class="highlight language-python"><span class="n">run</span><span class="p">()</span></code>
<a href="#smartmultiprocessing.SmartProcess.run" class="headerlink" title="Permanent link">¤</a></h2>
<div class="doc doc-contents "> <p>Runs the target of the process. </p><p>Not recommended: use <code>SmartProcess.start()</code> instead.</p>
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="smartmultiprocessing.SmartProcess.start" class="doc doc-heading"> <code class="highlight language-python"><span class="n">start</span><span class="p">()</span></code>
<a href="#smartmultiprocessing.SmartProcess.start" class="headerlink" title="Permanent link">¤</a></h2>
<div class="doc doc-contents "> <p>Starts the process.</p>
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="smartmultiprocessing.SmartProcess.join" class="doc doc-heading"> <code class="highlight language-python"><span class="n">join</span><span class="p">(</span><span class="n">timeout</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span></code>
<a href="#smartmultiprocessing.SmartProcess.join" class="headerlink" title="Permanent link">¤</a></h2>
<div class="doc doc-contents "> <p>Joins the thread of the process (assuming it has been started already) andblocks until completion.</p>
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="smartmultiprocessing.SmartProcess.is_alive" class="doc doc-heading"> <code class="highlight language-python"><span class="n">is_alive</span><span class="p">()</span></code>
<a href="#smartmultiprocessing.SmartProcess.is_alive" class="headerlink" title="Permanent link">¤</a></h2>
<div class="doc doc-contents "> <p>Boolean of whether or not the process is currently running.</p>
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="smartmultiprocessing.SmartProcess.is_finished" class="doc doc-heading"> <code class="highlight language-python"><span class="n">is_finished</span><span class="p">()</span></code>
<a href="#smartmultiprocessing.SmartProcess.is_finished" class="headerlink" title="Permanent link">¤</a></h2>
<div class="doc doc-contents "> <p>Boolean of whether or not the process has finished.</p>
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="smartmultiprocessing.SmartProcess.terminate" class="doc doc-heading"> <code class="highlight language-python"><span class="n">terminate</span><span class="p">(</span><span class="n">children</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span></code>
<a href="#smartmultiprocessing.SmartProcess.terminate" class="headerlink" title="Permanent link">¤</a></h2>
<div class="doc doc-contents "> <p>Sends a SIGTERM and terminates the process. TODO: document params</p>
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="smartmultiprocessing.SmartProcess.kill" class="doc doc-heading"> <code class="highlight language-python"><span class="n">kill</span><span class="p">(</span><span class="n">children</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span></code>
<a href="#smartmultiprocessing.SmartProcess.kill" class="headerlink" title="Permanent link">¤</a></h2>
<div class="doc doc-contents "> <p>Sends a SIGKILL and kills the process. TODO: document params</p>
</div>
</div>
<div class="doc doc-object doc-function">
<h2 id="smartmultiprocessing.SmartProcess.close" class="doc doc-heading"> <code class="highlight language-python"><span class="n">close</span><span class="p">()</span></code>
<a href="#smartmultiprocessing.SmartProcess.close" class="headerlink" title="Permanent link">¤</a></h2>
<div class="doc doc-contents "> <p>Closes all resources occupied by the process.</p>
</div>
</div>
</div>
</div>
</div>
</article> </div> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> </main> <footer class="md-footer"> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class="md-copyright"> Made with <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener"> Material for MkDocs </a> </div> </div> </div></footer> </div> <div class="md-dialog" data-md-component="dialog"> <div class="md-dialog__inner md-typeset"></div> </div> <script id="__config" type="application/json">{"base": "../..", "features": ["navigation.sections", "toc.integrate", "header.autohide", "search.suggest", "search.highlight", "search.share"], "search": "../../assets/javascripts/workers/search.b8dbb3d2.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}}</script> <script src="../../assets/javascripts/bundle.1e8ae164.min.js"></script> </body></html>