-
Notifications
You must be signed in to change notification settings - Fork 52
/
__init__.py
91 lines (71 loc) · 2.38 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# -*- coding: utf-8 -*-
"""
Oct2Py is a means to seamlessly call M-files and GNU Octave functions from Python.
It manages the Octave session for you, sharing data behind the scenes using
MAT files. Usage is as simple as:
.. code-block:: python
>>> import oct2py
>>> oc = oct2py.Oct2Py()
>>> x = oc.zeros(3,3)
>>> print(x, x.dtype.str) # doctest: +SKIP
[[ 0. 0. 0.]
[ 0. 0. 0.]
[ 0. 0. 0.]] <f8
If you want to run legacy m-files, do not have MATLAB(TM), and do not fully
trust a code translator, this is your library.
"""
__title__ = 'oct2py'
__version__ = '3.0.0'
__author__ = 'Steven Silvester'
__license__ = 'MIT'
__copyright__ = 'Copyright 2014 Steven Silvester'
__all__ = ['Oct2Py', 'Oct2PyError', 'octave', 'Struct', 'demo', 'speed_test',
'thread_test', '__version__', 'get_log']
import imp
import functools
import os
import ctypes
try:
import thread
except ImportError:
import _thread as thread
if os.name == 'nt':
"""
Allow Windows to intecept KeyboardInterrupt
http://stackoverflow.com/questions/15457786/ctrl-c-crashes-python-after-importing-scipy-stats
"""
basepath = imp.find_module('numpy')[1]
try:
lib1 = ctypes.CDLL(os.path.join(basepath, 'core', 'libmmd.dll'))
lib2 = ctypes.CDLL(os.path.join(basepath, 'core', 'libifcoremd.dll'))
def handler(sig, hook=thread.interrupt_main):
hook()
return 1
routine = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_uint)(handler)
ctypes.windll.kernel32.SetConsoleCtrlHandler(routine, 1)
except Exception:
pass
from .core import Oct2Py, Oct2PyError
from .utils import Struct, get_log
from .demo import demo
from .speed_check import speed_check
from .thread_check import thread_check
try:
octave = Oct2Py()
except Oct2PyError as e:
print(e)
def kill_octave():
"""Kill all octave instances (cross-platform).
This will restart the "octave" instance. If you have instantiated
Any other Oct2Py objects, you must restart them.
"""
import os
if os.name == 'nt':
os.system('taskkill /im octave /f')
else:
os.system('killall -9 octave')
os.system('killall -9 octave-cli')
octave.restart()
# clean up namespace
del functools, imp, os, ctypes, thread
del core, utils