FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/pythonnet/__init__.py at master · yport8/pythonnet · GitHub
yport8
pythonnet
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
pythonnet
/
__init__.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
60 lines (42 loc) · 1.43 KB
Breadcrumbs
pythonnet
/
pythonnet
/
__init__.py
Copy path
File metadata and controls
60 lines (42 loc) · 1.43 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
os
import
sys
import
clr_loader
_RUNTIME
=
None
_LOADER_ASSEMBLY
=
None
_FFI
=
None
_LOADED
=
False
def
set_runtime
(
runtime
):
global
_RUNTIME
if
_LOADED
:
raise
RuntimeError
(
"The runtime {runtime} has already been loaded"
.
format
(
_RUNTIME
))
_RUNTIME
=
runtime
def
set_default_runtime
()
->
None
:
if
sys
.
platform
==
'win32'
:
set_runtime
(
clr_loader
.
get_netfx
())
else
:
set_runtime
(
clr_loader
.
get_mono
())
def
load
():
global
_FFI
,
_LOADED
,
_LOADER_ASSEMBLY
if
_LOADED
:
return
from
os
.
path
import
join
,
dirname
if
_RUNTIME
is
None
:
# TODO: Warn, in the future the runtime must be set explicitly, either
# as a config/env variable or via set_runtime
set_default_runtime
()
dll_path
=
join
(
dirname
(
__file__
),
"runtime"
,
"Python.Runtime.dll"
)
_LOADER_ASSEMBLY
=
_RUNTIME
.
get_assembly
(
dll_path
)
func
=
_LOADER_ASSEMBLY
[
"Python.Runtime.Loader.Initialize"
]
if
func
(
''
.
encode
(
"utf8"
))
!=
0
:
raise
RuntimeError
(
"Failed to initialize Python.Runtime.dll"
)
import
atexit
atexit
.
register
(
unload
)
def
unload
():
global
_RUNTIME
if
_LOADER_ASSEMBLY
is
not
None
:
func
=
_LOADER_ASSEMBLY
[
"Python.Runtime.Loader.Shutdown"
]
if
func
(
b""
)
!=
0
:
raise
RuntimeError
(
"Failed to call Python.NET shutdown"
)
if
_RUNTIME
is
not
None
:
# TODO: Add explicit `close` to clr_loader
_RUNTIME
=
None
Back
|
FazBrowse Home
|
New Git URL