Popular recipes tagged "process" but not "cards"http://code.activestate.com/recipes/tags/process-cards/2014-05-30T01:10:53-07:00ActiveState Code RecipesMonitor Progress of File Descriptors of Another Process (Python) 2014-05-30T01:10:53-07:00Alfehttp://code.activestate.com/recipes/users/4182236/http://code.activestate.com/recipes/578882-monitor-progress-of-file-descriptors-of-another-pr/ <p style="color: grey"> Python recipe 578882 by <a href="/recipes/users/4182236/">Alfe</a> (<a href="/recipes/tags/file_descriptor/">file_descriptor</a>, <a href="/recipes/tags/monitor/">monitor</a>, <a href="/recipes/tags/prediction/">prediction</a>, <a href="/recipes/tags/proc/">proc</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/progress/">progress</a>, <a href="/recipes/tags/watch/">watch</a>). </p> <p>This tool (inspired by azat@stackoverflow, see <a href="http://stackoverflow.com/a/16082562/1281485" rel="nofollow">http://stackoverflow.com/a/16082562/1281485</a>) allows to watch the progress of the file descriptors of another process. This can be used, for example, if you transfer a file to another host and the transferring program does not show any progress indication itself. Instead of waiting blindly until the routine is done, with this tool you can use Linux's proc file system to monitor the progress of the other process while it walks through the file.</p> <p>The tool continuously monitors the position in and the size of the files the given process's file descriptors point to. For growing (or shrinking, but that's very unusual) files, a time when it was (or will be) empty is computed ("emptyTime"), for moving file descriptors (the typical case), the time when it started at position 0 ("startTime"), the time when it will reach the current size of the file ("reachTime") and when it will meet with the end of a growing (or shrinking) file is computed ("meetTime").</p> <p>For fixed-size files the meetTime will be the same as the reachTime of course. The meetTime only makes sense in case a file is growing and at the same time read (e. g. when a movie is downloaded to a file by one process and converted by a different process; using this tool can tell you when the converter process might run dry on the input because the download wasn't fast enough, and in this case you maybe can pause the converter to prevent this situation).</p> <p>The tool is designed as a library; the display of the information is independent from the gathering of the data. Please feel free to create more fancy displays, add percentage output etc.</p> Get memory usage of Windows processes using GetProcessMemoryInfo (via ctypes) (Python) 2013-04-25T01:26:19-07:00Ben Hoythttp://code.activestate.com/recipes/users/4170919/http://code.activestate.com/recipes/578513-get-memory-usage-of-windows-processes-using-getpro/ <p style="color: grey"> Python recipe 578513 by <a href="/recipes/users/4170919/">Ben Hoyt</a> (<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/memory/">memory</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/win32/">win32</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>These functions call the Win32 function GetProcessMemoryInfo() using ctypes to get the memory usage of the current process. Works on both 32-bit and 64-bit Windows and Python 2.6+ (including Python 3.x).</p> xdiff in python (Python) 2012-11-12T20:59:54-08:00Hirohttp://code.activestate.com/recipes/users/4184239/http://code.activestate.com/recipes/578324-xdiff-in-python/ <p style="color: grey"> Python recipe 578324 by <a href="/recipes/users/4184239/">Hiro</a> (<a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/process/">process</a>). Revision 2. </p> <p>xdiff.py compares and output difference of file1 and file2. it finds out the lines that are unique in file1 and files2, the finding is written to file3 and file4 respectively.</p> Get parent process pid win32 (Python) 2012-05-15T18:01:22-07:00nuumiohttp://code.activestate.com/recipes/users/4182080/http://code.activestate.com/recipes/578133-get-parent-process-pid-win32/ <p style="color: grey"> Python recipe 578133 by <a href="/recipes/users/4182080/">nuumio</a> (<a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/process_management/">process_management</a>). </p> <p>Use ctypes + Win32 functions to enumerate processes and find parent process id.</p> <p>Thanks to winterTTr Dong for the original recipe.</p> Wait for PID and check for PID existance (POSIX) (Python) 2012-04-15T14:13:02-07:00Giampaolo RodolĂ http://code.activestate.com/recipes/users/4178764/http://code.activestate.com/recipes/578022-wait-for-pid-and-check-for-pid-existance-posix/ <p style="color: grey"> Python recipe 578022 by <a href="/recipes/users/4178764/">Giampaolo RodolĂ </a> (<a href="/recipes/tags/exists/">exists</a>, <a href="/recipes/tags/exit/">exit</a>, <a href="/recipes/tags/pid/">pid</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/status/">status</a>, <a href="/recipes/tags/timeout/">timeout</a>, <a href="/recipes/tags/wait/">wait</a>). Revision 7. </p> <p>Two functions: one which waits for a certain PID to terminate (with optional timeout), another one which checks whether a process with a given PID is running.</p> <p>This was extracted from <a href="http://code.google.com/p/psutil/">psutil</a> project which also provides a Windows implementation.</p> <p>Timeout functionality is implemented as a busy loop and it was inspired by <a href="http://bugs.python.org/issue5673." rel="nofollow">http://bugs.python.org/issue5673.</a></p> Generic way to create a daemonized process in python (Python) 2012-03-26T14:56:17-07:00ajaymenon.khttp://code.activestate.com/recipes/users/4181225/http://code.activestate.com/recipes/578072-generic-way-to-create-a-daemonized-process-in-pyth/ <p style="color: grey"> Python recipe 578072 by <a href="/recipes/users/4181225/">ajaymenon.k</a> (<a href="/recipes/tags/daemon/">daemon</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/threads/">threads</a>). Revision 4. </p> <p>A simple daemon that will constantly keep track the size of your inbox and when it exceeds a certain size, will send you a reminder email.</p> Win32 named mutex class for system-wide mutex (Python) 2011-07-15T21:12:40-07:00Ben Hoythttp://code.activestate.com/recipes/users/4170919/http://code.activestate.com/recipes/577794-win32-named-mutex-class-for-system-wide-mutex/ <p style="color: grey"> Python recipe 577794 by <a href="/recipes/users/4170919/">Ben Hoyt</a> (<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/lock/">lock</a>, <a href="/recipes/tags/mutex/">mutex</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/threading/">threading</a>, <a href="/recipes/tags/win32/">win32</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>NamedMutex is a class for using Windows (Win32) named mutexes for system-wide locks. For example, we use these to lock system-wide log files that multiple processes can write to.</p> Sleepsort with processes and pipes (Python) 2011-06-17T02:37:58-07:00Benjamin Petersonhttp://code.activestate.com/recipes/users/4170802/http://code.activestate.com/recipes/577758-sleepsort-with-processes-and-pipes/ <p style="color: grey"> Python recipe 577758 by <a href="/recipes/users/4170802/">Benjamin Peterson</a> (<a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/sorting/">sorting</a>, <a href="/recipes/tags/unix/">unix</a>). Revision 2. </p> <p>Sleepsort is a sorting algorithm that uses the system sleep syscall in a very creative fashion.</p> <p>This is the same algorithm as <a href="http://code.activestate.com/recipes/577756/">recipe 577756</a> but using *nix processes instead of threads.</p> Simple way to execute multiple process in parallel (Python) 2010-08-31T00:11:00-07:00Benjamin Sergeanthttp://code.activestate.com/recipes/users/4039626/http://code.activestate.com/recipes/577376-simple-way-to-execute-multiple-process-in-parallel/ <p style="color: grey"> Python recipe 577376 by <a href="/recipes/users/4039626/">Benjamin Sergeant</a> (<a href="/recipes/tags/multiprocessing/">multiprocessing</a>, <a href="/recipes/tags/process/">process</a>). Revision 4. </p> <p>Does not require multiprocessing, easy to hack, maybe not optimal but did the job for a make like tool I wrote.</p> Multiprocess-safe logging file-handler + interprocess RLock (Python) 2010-09-22T17:30:10-07:00Jan Kaliszewskihttp://code.activestate.com/recipes/users/4172762/http://code.activestate.com/recipes/577395-multiprocess-safe-logging-file-handler-interproces/ <p style="color: grey"> Python recipe 577395 by <a href="/recipes/users/4172762/">Jan Kaliszewski</a> (<a href="/recipes/tags/concurrency/">concurrency</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/file_lock/">file_lock</a>, <a href="/recipes/tags/flock/">flock</a>, <a href="/recipes/tags/handler/">handler</a>, <a href="/recipes/tags/logging/">logging</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/rlock/">rlock</a>, <a href="/recipes/tags/threading/">threading</a>, <a href="/recipes/tags/threadsafe/">threadsafe</a>). Revision 11. </p> <p>A Python 2.x/3.x-compatibile <strong>multiprocess-safe logging file-handler</strong> (logging.FileHandler replacement, designed for logging to a single file from multiple independent processes) together with a simple <strong>interprocess recursive lock</strong> -- universal abstract classes + Unix/Linux implementation.</p> <p><strong>Update:</strong> It's is a deeply revised version. Especially, now it --</p> <ul> <li>is Python 2.4, 2.5, 2.6, 3.1 -compatibile (previously Py>=2.6 was needed); probably works also with 2.7, 3.0 and 3.2 (but not tested if it does);</li> <li>is multiprocess-safe as well as thread-safe (proviously thread safety within a process was missed);</li> <li>is based on public interfaces only (previously FileHandler._open() was called and overriden);</li> <li>implement full RLock instance interface, as documented for threading.RLock (previously non-blocking mode and context-manager interface were missing).</li> </ul> <p>The module contains:</p> <ul> <li>Unix/Linux-only example implementation (with flock-based locking): <strong>FLockRLock</strong> and <strong>FLockFileHandler</strong> classes.</li> <li>universal abstract classes -- which may be useful at developing implementation for non-Unix platforms: <strong>MultiprocessRLock</strong>, <strong>MultiprocessFileHandler</strong>, <strong>LockedFileHandler</strong>,</li> </ul> <p>Also a quick-and-dirty test was added.</p> <p><strong>It is still an alpha version -- I'll be very grateful for any feedback.</strong></p> <hr /> <p><strong>Further updates:</strong></p> <ul> <li><p>2010-09-20: Some corrections, especially: non-blocking mode bug in MultiprocessRLock.acquire() fixed; _test() function improved; plus fixes in the description below.</p></li> <li><p>2010-09-22: _test() improved and moved to description section. Mistaken copyright-notice removed.</p></li> </ul> fcntl.flock() (Unix file lock) behaviour sampling script (Python) 2010-09-22T00:11:12-07:00Jan Kaliszewskihttp://code.activestate.com/recipes/users/4172762/http://code.activestate.com/recipes/577404-fcntlflock-unix-file-lock-behaviour-sampling-scrip/ <p style="color: grey"> Python recipe 577404 by <a href="/recipes/users/4172762/">Jan Kaliszewski</a> (<a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/file_descriptor/">file_descriptor</a>, <a href="/recipes/tags/file_lock/">file_lock</a>, <a href="/recipes/tags/flock/">flock</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/thread/">thread</a>). Revision 3. </p> <p>A quick <em>fcntl.flock(fcntl.LOCK_EX | fcntl.LOCK_NB)</em> call sampling script: with <em>one file object</em> (and descriptor) or <em>separate file objects</em> (and different descriptors) pointing to the same filesystem path -- with/without <strong>threading</strong> or <strong>forking</strong>.</p> <p>It's rather exemplum-and-educational piece of code than utility-script, unless somebody has to few slots in their memory to remember that <strong>flock</strong> is file-descriptor-tacked (then quick run of the script can save web-searching) :)</p> Decoupled Proxy of a State Bearing Object in a Multiprocessing Environment (Python) 2010-04-08T04:36:05-07:00Mateyuzohttp://code.activestate.com/recipes/users/4172453/http://code.activestate.com/recipes/577180-decoupled-proxy-of-a-state-bearing-object-in-a-mul/ <p style="color: grey"> Python recipe 577180 by <a href="/recipes/users/4172453/">Mateyuzo</a> (<a href="/recipes/tags/access/">access</a>, <a href="/recipes/tags/multiprocessing/">multiprocessing</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/processing/">processing</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/synchronization/">synchronization</a>, <a href="/recipes/tags/syncmanager/">syncmanager</a>, <a href="/recipes/tags/threading/">threading</a>, <a href="/recipes/tags/__getattribute__/">__getattribute__</a>). Revision 2. </p> <p>Describes a simple example of the potential for shared Singleton or Borg object methods to be proxy'd by an object that SyncManger can present to requesting subprocesses.</p> Timeout Any Function (Python) 2010-02-04T17:36:31-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577028-timeout-any-function/ <p style="color: grey"> Python recipe 577028 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/asynchronous/">asynchronous</a>, <a href="/recipes/tags/generic/">generic</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/timeout/">timeout</a>, <a href="/recipes/tags/universal_code/">universal_code</a>). Revision 6. </p> <p>This recipe uses the <code>multiprocessing</code> module to kill functions that have run longer than intended. Unlike other recipes that use threading, this code is designed to actually kill execution that has continued for too long. This implementation does not rely on signals or anything that is OS specific, so it should work on any system on which you might need generic timeouts.</p> Super Shorcuts for Windows (Python) 2009-04-26T11:09:39-07:00Akira Forahttp://code.activestate.com/recipes/users/4114779/http://code.activestate.com/recipes/576730-super-shorcuts-for-windows/ <p style="color: grey"> Python recipe 576730 by <a href="/recipes/users/4114779/">Akira Fora</a> (<a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/windows/">windows</a>, <a href="/recipes/tags/wmi/">wmi</a>). </p> <p>This script allows one to launch or kill several applications at once. It works on MS Windows.</p> Run a function in a separate (forked) process without blocking (Python) 2008-02-28T22:22:18-08:00Gary Eakinshttp://code.activestate.com/recipes/users/470921/http://code.activestate.com/recipes/550801-run-a-function-in-a-separate-forked-process-withou/ <p style="color: grey"> Python recipe 550801 by <a href="/recipes/users/470921/">Gary Eakins</a> (<a href="/recipes/tags/fork/">fork</a>, <a href="/recipes/tags/mmap/">mmap</a>, <a href="/recipes/tags/process/">process</a>). Revision 2. </p> <p>A procedure that runs a function asynchronously in a forked process (Availability: Macintosh, Unix). The return from the specified function is written into an anonymous memory map (mmap: requires +Python 2.5). This can be useful for releasing resources used by the function such as memory, updating a gui or cli widget, or other weirdness.</p> An Erlang Port in Python (Python) 2010-02-18T06:47:09-08:00thanos vassilakishttp://code.activestate.com/recipes/users/4048784/http://code.activestate.com/recipes/534162-an-erlang-port-in-python/ <p style="color: grey"> Python recipe 534162 by <a href="/recipes/users/4048784/">thanos vassilakis</a> (<a href="/recipes/tags/distributed/">distributed</a>, <a href="/recipes/tags/erlang/">erlang</a>, <a href="/recipes/tags/integration/">integration</a>, <a href="/recipes/tags/process/">process</a>). Revision 3. </p> <p>Erlang has two built-in interoperability mechanisms. One is distributed Erlang nodes and the other one is ports. Ports provide the basic Erlang mechanism for communication with the external world. They provide a byte-oriented interface to an external program. When a port has been created, Erlang can communicate with it by sending and receiving lists of bytes. This recipe cooks an Erlang port in python. Making it easy for Erlang to instantiate and use python objects. Like most simple port implementations it uses an external python program and lets Erlang communicate via standard input and write to standard output. Theoretically, the external program could be written in any programming language. This recipe is pretty abstract and you will have to implement your own encode and decoding scheme.</p>