Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hidra
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
steinbac
hidra
Commits
1fe15f8a
Commit
1fe15f8a
authored
9 years ago
by
Manuela Kuhn
Browse files
Options
Downloads
Patches
Plain Diff
Fixed SignalHandler for Windows
parent
78ce5440
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/sender/SignalHandler.py
+90
-29
90 additions, 29 deletions
src/sender/SignalHandler.py
with
90 additions
and
29 deletions
src/sender/SignalHandler.py
+
90
−
29
View file @
1fe15f8a
...
...
@@ -11,11 +11,14 @@ import cPickle
from
multiprocessing
import
Process
#path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
try
:
BASE_PATH
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)
)))
except
:
BASE_PATH
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
'
__file__
'
)
)))
# BASE_PATH = os.path.dirname ( os.path.dirname ( os.path.dirname ( os.path.abspath ( sys.argv[0] ) )))
print
"
Signal: BASE_PATH
"
,
BASE_PATH
#SHARED_PATH = os.path.dirname ( os.path.dirname ( os.path.realpath ( __file__ ) ) ) + os.sep + "shared"
SHARED_PATH
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
sys
.
argv
[
0
]
)
)
)
+
os
.
sep
+
"
shared
"
print
SHARED_PATH
SHARED_PATH
=
BASE_PATH
+
os
.
sep
+
"
src
"
+
os
.
sep
+
"
shared
"
if
not
SHARED_PATH
in
sys
.
path
:
sys
.
path
.
append
(
SHARED_PATH
)
...
...
@@ -29,7 +32,8 @@ import helpers
class
SignalHandler
():
def
__init__
(
self
,
whiteList
,
comPort
,
signalFwPort
,
requestPort
,
context
=
None
):
logConfig
=
None
,
context
=
None
):
print
"
__init__
"
# to get the logging only handling this class
log
=
None
...
...
@@ -61,8 +65,16 @@ class SignalHandler():
self
.
requestFwSocket
=
None
self
.
requestSocket
=
None
self
.
log
=
self
.
getLogger
()
# Recreate the logger in the child
if
logConfig
:
logfile
=
BASE_PATH
+
os
.
sep
+
"
logs
"
+
os
.
sep
+
"
signalHandler_.log
"
helpers
.
initLogging
(
logfile
,
verbose
=
True
,
onScreenLogLevel
=
"
debug
"
)
# logging.config.dictConfig(logConfig)
self
.
log
=
self
.
getLogger
()
self
.
log
.
debug
(
"
Init
"
)
print
"
init logger
"
self
.
createSockets
()
...
...
@@ -345,37 +357,48 @@ class SignalHandler():
self
.
stop
()
if
__name__
==
'
__main__
'
:
# cannot be defined in "if __name__ == '__main__'" because then it is unbound
# see https://docs.python.org/2/library/multiprocessing.html#windows
class
requestPuller
():
def
__init__
(
self
,
requestFwPort
,
logConfig
=
None
,
context
=
None
):
from
multiprocessing
import
Process
import
time
if
logConfig
:
logfile
=
BASE_PATH
+
os
.
sep
+
"
logs
"
+
os
.
sep
+
"
signalHandler__.log
"
helpers
.
initLogging
(
logfile
,
verbose
=
True
,
onScreenLogLevel
=
"
debug
"
)
class
requestPuller
():
def
__init__
(
self
,
requestFwPort
,
context
=
None
):
self
.
context
=
context
or
zmq
.
Context
.
instance
()
self
.
requestFwSocket
=
self
.
context
.
socket
(
zmq
.
REQ
)
connectionStr
=
"
tcp://localhost:
"
+
requestFwPort
self
.
requestFwSocket
.
connect
(
connectionStr
)
logging
.
info
(
"
[getRequests] requestFwSocket started (connect) for
'"
+
connectionStr
+
"'"
)
self
.
run
()
self
.
context
=
context
or
zmq
.
Context
.
instance
()
self
.
requestFwSocket
=
self
.
context
.
socket
(
zmq
.
REQ
)
connectionStr
=
"
tcp://localhost:
"
+
requestFwPort
self
.
requestFwSocket
.
connect
(
connectionStr
)
logging
.
info
(
"
[getRequests] requestFwSocket started (connect) for
'"
+
connectionStr
+
"'"
)
self
.
run
()
def
run
(
self
):
logging
.
info
(
"
[getRequests] Start run
"
)
while
True
:
def
run
(
self
):
logging
.
info
(
"
[getRequests] Start run
"
)
while
True
:
try
:
self
.
requestFwSocket
.
send
(
""
)
logging
.
info
(
"
[getRequests] send
"
)
requests
=
cPickle
.
loads
(
self
.
requestFwSocket
.
recv
())
logging
.
info
(
"
[getRequests] Requests:
"
+
str
(
requests
))
time
.
sleep
(
0.25
)
except
Exception
as
e
:
logging
.
error
(
str
(
e
))
break
def
__exit__
(
self
):
self
.
requestFwSocket
.
close
(
0
)
self
.
context
.
destroy
()
def
__exit__
(
self
)
:
self
.
requestFwSocket
.
close
(
0
)
self
.
context
.
destroy
()
if
__name__
==
'
__main__
'
:
from
multiprocessing
import
Process
,
freeze_support
import
time
# BASE_PATH = os.path.dirname ( os.path.dirname ( os.path.dirname ( os.path.realpath ( __file__ ) )))
BASE_PATH
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
sys
.
argv
[
0
]
)
)))
freeze_support
()
#see https://docs.python.org/2/library/multiprocessing.html#windows
logfile
=
BASE_PATH
+
os
.
sep
+
"
logs
"
+
os
.
sep
+
"
signalHandler.log
"
helpers
.
initLogging
(
logfile
,
verbose
=
True
,
onScreenLogLevel
=
"
debug
"
)
...
...
@@ -385,10 +408,48 @@ if __name__ == '__main__':
comPort
=
"
6000
"
requestFwPort
=
"
6001
"
requestPort
=
"
6002
"
signalHandlerProcess
=
Process
(
target
=
SignalHandler
,
args
=
(
whiteList
,
comPort
,
requestFwPort
,
requestPort
)
)
logConfig
=
{
'
version
'
:
1
,
'
disable_existing_loggers
'
:
False
,
'
formatters
'
:
{
'
standard
'
:
{
'
format
'
:
'
[%(asctime)s] [PID %(process)d] [%(filename)s] [%(module)s:%(funcName)s:%(lineno)d] [%(name)s] [%(levelname)s] %(message)s
'
},
},
'
handlers
'
:
{
'
default
'
:
{
'
level
'
:
'
DEBUG
'
,
'
class
'
:
'
logging.StreamHandler
'
,
},
'
logging.handlers.RotatingFileHandler
'
:
{
'
level
'
:
'
DEBUG
'
,
'
format
'
:
'
brief
'
,
'
filename
'
:
logfile
,
'
maxBytes
'
:
1024
,
'
backupCount
'
:
3
},
},
'
loggers
'
:
{
''
:
{
'
handlers
'
:
[
'
default
'
],
'
level
'
:
'
INFO
'
,
'
propagate
'
:
True
},
}
}
# logging.basicConfig(level=loggingLevel,
# format='[%(asctime)s] [PID %(process)d] [%(filename)s] [%(module)s:%(funcName)s:%(lineno)d] [%(name)s] [%(levelname)s] %(message)s',
# datefmt='%Y-%m-%d_%H:%M:%S',
# filename=filenameFullPath,
# filemode="a")
signalHandlerProcess
=
Process
(
target
=
SignalHandler
,
args
=
(
whiteList
,
comPort
,
requestFwPort
,
requestPort
,
logConfig
)
)
signalHandlerProcess
.
start
()
requestPullerProcess
=
Process
(
target
=
requestPuller
,
args
=
(
requestFwPort
,
)
)
requestPullerProcess
=
Process
(
target
=
requestPuller
,
args
=
(
requestFwPort
,
logConfig
)
)
requestPullerProcess
.
start
()
...
...
@@ -417,12 +478,12 @@ if __name__ == '__main__':
context
=
zmq
.
Context
.
instance
()
comSocket
=
context
.
socket
(
zmq
.
REQ
)
connectionStr
=
"
tcp://
zitpcx19282
:
"
+
comPort
connectionStr
=
"
tcp://
localhost
:
"
+
comPort
comSocket
.
connect
(
connectionStr
)
logging
.
info
(
"
=== comSocket connected to
"
+
connectionStr
)
requestSocket
=
context
.
socket
(
zmq
.
PUSH
)
connectionStr
=
"
tcp://
zitpcx19282
:
"
+
requestPort
connectionStr
=
"
tcp://
localhost
:
"
+
requestPort
requestSocket
.
connect
(
connectionStr
)
logging
.
info
(
"
=== requestSocket connected to
"
+
connectionStr
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment