geosoft.gxpy.system submodule¶
Geosoft system functions.
Note
Regression tests provide usage examples: Tests
-
exception
GXSysException
(message)[source]¶ Bases:
geosoft.GXRuntimeError
Exceptions from
geosoft.gxpy.system
.New in version 9.1.
-
call_location
(stack=0)[source]¶ Returns function call location including file and line number as a string
- Parameters
stack – depth into the calling stack, 0 (default) is this function, 1 is parent, etc.
- Returns
string formatted as ‘<file>, line XX in <function>’, empty string if too deep into the stack
New in version 9.2.
-
func_name
(stack=0)[source]¶ Returns function name.
- Parameters
stack – depth into the calling stack, 0 (default) is this function, 1 is parent, etc.
- Returns
function name, None if too deep into the stack
Changed in version 9.2: added stack
New in version 9.1.
-
parallel_map
(f, l, threads=None)[source]¶ A parallel equivalent of the map() built-in Python function (it supports only one iterable argument though).
- Parameters
f – function to run in parallel f(). Must be thread-safe, of course.
l – iterable list of arguments to pass to each thread. Use tuples for multiple arguments.
threads – number of threads to use, default is number of cores on computer
- Returns
list of results from each call to f(), in order of iterable l.
- Example
import gxpy.system as gsys def func(ab): ''' :param ab: tuple (a,b) :returns: a+b ''' return ab[0] + ab[1] # create list of 20 argument sets to calculate in parallel data = [(1+i, 2+i) for i in range(20)] # print results of running function in parallel print(gsys.parallel_map(func, data)) # prints: [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41] # same thing using a lambda function print(gsys.parallel_map(lambda ab: ab[0] + ab[1], data))
New in version 9.1.
-
remove_dir
(directory, wait=200, tries=10)[source]¶ Robust directory removal, with timed retries to allow for OS timing lags. If you need to use this you may have a coding error in which you are not properly releasing a resource.
- Parameters
directory – directory name, must be a directory
wait – wait between retries in milliseconds
tries – number of times to retry
New in version 9.1.
-
unzip
(zip_file_name, folder=None, report=None, checkready=25)[source]¶ Decompress and write the content of a zip file to a folder.
- Parameters
zip_file_name – zip file name, must have extension
folder – folder to write results, create it it does not exist
report – ignored
checkready – time in 1/10 second to check completion of each file, default 25
- Returns
(folder that contains unzipped files, list of files)
New in version 9.1.
-
wait_on_file
(fileName, wait=100, retries=10)[source]¶ Working with large files on systems that cache the file can cause a situation where the file is not yet completely written out before an attempt is made to open a file that has just been closed.
Call this function to wait for the file to be available. Best to do this right after you know that you may have written out a large file, or in a try/except around a file open.
- Parameters
fileName –
- Wait
time in milliseconds to wait between retries
- Retries
maximum number of retries
- Raises
GX_SysException if fail to get read access to the file.
New in version 9.1.