File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -29,9 +29,23 @@ class PayloadManager(Configurable):
2929
3030 _payload = List ([])
3131
32- def write_payload (self , data ):
32+ def write_payload (self , data , single = True ):
33+ """Include or update the specified `data` payload in the PayloadManager.
34+
35+ If a previous payload with the same source exists and `single` is True,
36+ it will be overwritten with the new one.
37+ """
38+
3339 if not isinstance (data , dict ):
3440 raise TypeError ('Each payload write must be a dict, got: %r' % data )
41+
42+ if single and 'source' in data :
43+ source = data ['source' ]
44+ for i , pl in enumerate (self ._payload ):
45+ if 'source' in pl and pl ['source' ] == source :
46+ self ._payload [i ] = data
47+ return
48+
3549 self ._payload .append (data )
3650
3751 def read_payload (self ):
Original file line number Diff line number Diff line change @@ -406,6 +406,15 @@ def test_kernel_info_request():
406406 validate_message (reply , 'kernel_info_reply' , msg_id )
407407
408408
409+ def test_single_payload ():
410+ flush_channels ()
411+ msg_id , reply = execute (code = "for i in range(3):\n " +
412+ " x=range?\n " )
413+ payload = reply ['payload' ]
414+ next_input_pls = [pl for pl in payload if pl ["source" ] == "set_next_input" ]
415+ nt .assert_equal (len (next_input_pls ), 1 )
416+
417+
409418# IOPub channel
410419
411420
You can’t perform that action at this time.
0 commit comments