Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Yuan Zhixiang
c-backend-docker
Commits
5cab7ab1
Commit
5cab7ab1
authored
Apr 28, 2024
by
Yuan Zhixiang
Browse files
修复 kill任务时临时文件夹不会被删除的bug
parent
cfb78256
Changes
1
Show whitespace changes
Inline
Side-by-side
c-backend/backend.py
View file @
5cab7ab1
...
...
@@ -6,6 +6,8 @@ from gevent.pywsgi import WSGIServer
from
flask_cors
import
CORS
import
psutil
import
signal
import
os
import
shutil
app
=
Flask
(
__name__
)
CORS
(
app
)
...
...
@@ -68,9 +70,20 @@ def run_python2_script_and_get_output(code, stdin):
for
child
in
children
:
child
.
send_signal
(
signal
.
SIGKILL
)
process
.
send_signal
(
signal
.
SIGKILL
)
remove_random_temp_folders
()
return
'timeout'
# 移除 run_cpp_backend.py 创建的随机临时文件夹
def
remove_random_temp_folders
():
for
item
in
os
.
listdir
(
'.'
):
if
os
.
path
.
isdir
(
item
)
and
len
(
item
)
==
36
:
try
:
shutil
.
rmtree
(
item
)
except
Exception
as
remove_random_temp_folders_e
:
print
(
remove_random_temp_folders_e
)
if
__name__
==
'__main__'
:
print
(
'c-backend server start.'
)
r
=
redis
.
Redis
(
host
=
'c-redis-service'
,
password
=
'c-backend'
,
port
=
6379
,
decode_responses
=
True
)
...
...
@@ -78,8 +91,8 @@ if __name__ == '__main__':
r
.
ping
()
redis_available
=
True
print
(
'redis: connected.'
)
except
redis
.
exceptions
.
ConnectionError
as
e
:
print
(
'redis: failed.'
,
e
)
except
redis
.
exceptions
.
ConnectionError
as
redis_
e
:
print
(
'redis: failed.'
,
redis_
e
)
# 启动后端
http_server
=
WSGIServer
((
''
,
5000
),
app
)
http_server
.
serve_forever
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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