Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
7a3e4c4d
Commit
7a3e4c4d
authored
Jun 06, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move send-queue to simulatormaster
parent
c12cf88b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
2 deletions
+9
-2
tensorpack/RL/simulator.py
tensorpack/RL/simulator.py
+9
-2
No files found.
tensorpack/RL/simulator.py
View file @
7a3e4c4d
...
@@ -59,7 +59,7 @@ class SimulatorProcess(multiprocessing.Process):
...
@@ -59,7 +59,7 @@ class SimulatorProcess(multiprocessing.Process):
action
=
loads
(
data
)
action
=
loads
(
data
)
reward
,
isOver
=
player
.
action
(
action
)
reward
,
isOver
=
player
.
action
(
action
)
c2s_socket
.
send
(
dumps
((
reward
,
isOver
)),
copy
=
False
)
c2s_socket
.
send
(
dumps
((
reward
,
isOver
)),
copy
=
False
)
noop
=
s2c_socket
.
recv
(
copy
=
False
)
ACK
=
s2c_socket
.
recv
(
copy
=
False
)
#cnt += 1
#cnt += 1
#if cnt % 100 == 0:
#if cnt % 100 == 0:
#print_total_timer()
#print_total_timer()
...
@@ -102,6 +102,13 @@ class SimulatorMaster(threading.Thread):
...
@@ -102,6 +102,13 @@ class SimulatorMaster(threading.Thread):
self
.
socket_lock
=
threading
.
Lock
()
self
.
socket_lock
=
threading
.
Lock
()
self
.
daemon
=
True
self
.
daemon
=
True
# queueing messages to client
self
.
send_queue
=
queue
.
Queue
(
maxsize
=
50
)
self
.
send_thread
=
LoopThread
(
lambda
:
self
.
s2c_socket
.
send_multipart
(
self
.
send_queue
.
get
()))
self
.
send_thread
.
start
()
# make sure socket get closed at the end
def
clean_context
(
soks
,
context
):
def
clean_context
(
soks
,
context
):
for
s
in
soks
:
for
s
in
soks
:
s
.
close
()
s
.
close
()
...
@@ -113,7 +120,6 @@ class SimulatorMaster(threading.Thread):
...
@@ -113,7 +120,6 @@ class SimulatorMaster(threading.Thread):
self
.
clients
=
defaultdict
(
SimulatorMaster
.
ClientState
)
self
.
clients
=
defaultdict
(
SimulatorMaster
.
ClientState
)
while
True
:
while
True
:
ident
,
msg
=
self
.
c2s_socket
.
recv_multipart
()
ident
,
msg
=
self
.
c2s_socket
.
recv_multipart
()
#assert _ == ""
client
=
self
.
clients
[
ident
]
client
=
self
.
clients
[
ident
]
client
.
protocol_state
=
1
-
client
.
protocol_state
# first flip the state
client
.
protocol_state
=
1
-
client
.
protocol_state
# first flip the state
if
not
client
.
protocol_state
==
0
:
# state-action
if
not
client
.
protocol_state
==
0
:
# state-action
...
@@ -126,6 +132,7 @@ class SimulatorMaster(threading.Thread):
...
@@ -126,6 +132,7 @@ class SimulatorMaster(threading.Thread):
self
.
_on_episode_over
(
ident
)
self
.
_on_episode_over
(
ident
)
else
:
else
:
self
.
_on_datapoint
(
ident
)
self
.
_on_datapoint
(
ident
)
self
.
send_queue
.
put
([
ident
,
'Thanks'
])
# just an ACK
@
abstractmethod
@
abstractmethod
def
_on_state
(
self
,
state
,
ident
):
def
_on_state
(
self
,
state
,
ident
):
...
...
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