Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
c_call_python
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanli
c_call_python
Commits
d673830a
Commit
d673830a
authored
Oct 27, 2021
by
wanli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🧪 test: 更新测试用例
parent
8b380051
Pipeline
#586
failed with stages
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
74 additions
and
2 deletions
+74
-2
cpython.pro
cpython.pro
+4
-1
fastapi_main.py
fastapi_main.py
+35
-0
graph.py
graph.py
+2
-1
hello.py
hello.py
+14
-0
main.c
main.c
+1
-0
test_StartServer.c
test_StartServer.c
+17
-0
test_case.h
test_case.h
+1
-0
No files found.
cpython.pro
View file @
d673830a
...
...
@@ -16,10 +16,13 @@ SOURCES += \
test_CallPythonFunction
.
c
\
test_CallPythonSentiment
.
c
\
test_CallScript
.
c
\
test_RunSimpleString
.
c
test_RunSimpleString
.
c
\
test_StartServer
.
c
DISTFILES
+=
\
fastapi_main
.
py
\
graph
.
py
\
hello
.
py
\
sample
.
py
\
demo
.
py
\
multiply
.
py
\
...
...
fastapi_main.py
0 → 100644
View file @
d673830a
import
json
import
uvicorn
from
typing
import
Optional
from
fastapi
import
FastAPI
app
=
FastAPI
()
@
app
.
get
(
"/"
)
def
read_root
():
return
{
"Hello"
:
"World"
}
@
app
.
get
(
"/items/{item_id}"
)
def
read_item
(
item_id
:
int
,
q
:
Optional
[
str
]
=
None
):
return
{
"item_id"
:
item_id
,
"q"
:
q
}
@
app
.
get
(
"/json"
)
def
get_json
():
result
=
{
"xxx"
:
"started by cpython"
}
if
result
:
result
=
json
.
loads
(
result
)
return
result
def
start_server
():
print
(
"start web service...."
)
uvicorn
.
run
(
app
=
'fastapi_main:app'
,
host
=
"0.0.0.0"
,
port
=
58000
,
reload
=
True
,
log_level
=
"info"
,
workers
=
1
)
if
__name__
==
'__main__'
:
start_server
()
graph.py
View file @
d673830a
...
...
@@ -3,7 +3,7 @@ import xlsxwriter
def
create_graph
(
a
,
b
,
c
,
d
,
e
,
f
):
# 创建一个excel
# 创建一个excel
workbook
=
xlsxwriter
.
Workbook
(
"排序算法比较结果.xlsx"
)
# 创建一个sheet
worksheet
=
workbook
.
add_worksheet
()
...
...
@@ -49,5 +49,6 @@ def create_graph(a, b, c, d, e, f):
workbook
.
close
()
return
0
if
__name__
==
"__main__"
:
create_graph
(
10
,
40
,
50
,
20
,
10
,
50
)
hello.py
0 → 100644
View file @
d673830a
from
flask
import
Flask
app
=
Flask
(
__name__
)
@
app
.
route
(
'/'
)
def
hello
():
return
'Hello, World!'
def
start
():
app
.
run
()
if
__name__
==
'__main__'
:
start
()
\ No newline at end of file
main.c
View file @
d673830a
...
...
@@ -22,6 +22,7 @@ int main(int argc, const char* argv[])
test_CallModuleClass
();
// 调用模块中简单的一个类(单个返回值)
test_CallModuleClassReturnTuple
();
// 调用模块中一个简单的类(返回值是个元组)
test_CallScript
();
// 调用一个python脚本
test_StartServer
();
system
(
"PAUSE"
);
return
0
;
...
...
test_StartServer.c
0 → 100644
View file @
d673830a
#include "test_case.h"
void
test_StartServer
()
{
Py_Initialize
();
getCurrentEnv
();
PyObject
*
pModule
=
NULL
,
*
pMethod
=
NULL
,
*
pArg
=
NULL
;
pModule
=
PyImport_ImportModule
(
"hello"
);
pMethod
=
PyObject_GetAttrString
(
pModule
,
"start"
);
pArg
=
Py_BuildValue
(
"()"
,
NULL
);
PyEval_CallObject
(
pMethod
,
pArg
);
printf
(
"is blocked ???"
);
Py_Finalize
();
}
test_case.h
View file @
d673830a
...
...
@@ -11,6 +11,7 @@ void test_CallModuleFunctionByParameters(void);
void
test_CallModuleClass
(
void
);
void
test_CallScript
(
void
);
void
test_CallModuleClassReturnTuple
(
void
);
void
test_StartServer
(
void
);
float
getSentiment
(
char
*
sentence
);
void
getCurrentEnv
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment