hi,

> I needed the following patch to use debug console.
> 
>>From 56e7c458273d5acf7a9202df39ae4e8617875c56 Mon Sep 17 00:00:00 2001
> Message-Id: 
> <56e7c458273d5acf7a9202df39ae4e8617875c56.1365057932.git.yamah...@valinux.co.jp>
> From: Isaku Yamahata <[email protected]>
> Date: Thu, 4 Apr 2013 15:40:37 +0900
> Subject: [PATCH] debug_console: monkey patch
>  code.InterractiveConsole.raw_input
> 
> By default code.InteractiveConsole.raw_input uses builtin raw_input
> which is written in C. So it may not yeild thread execution, and other
> threads aren't scheduled.
> replace code.InteractiveConsole.raw_input with thread friendly one.
> Thus Ryu works as expected with debug_console app.

you are right.
the attached one is what i have in my local tree.

YAMAMOTO Takashi

> 
> Signed-off-by: Isaku Yamahata <[email protected]>
> ---
>  ryu/app/debug_console.py |    8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/ryu/app/debug_console.py b/ryu/app/debug_console.py
> index ab9d3a2..e0cacec 100644
> --- a/ryu/app/debug_console.py
> +++ b/ryu/app/debug_console.py
> @@ -25,13 +25,19 @@ import signal
>  from ryu.base import app_manager
>  
>  
> +# builtin raw_input() is written by C and doesn't yeild execution.
> +def _raw_input(message):
> +    sys.stdout.write(message)
> +    gevent.socket.wait_read(sys.stdin.fileno())
> +    return sys.stdin.readline()
> +
>  class DebugConsole(app_manager.RyuApp):
>      def __init__(self, *args, **kwargs):
>          super(DebugConsole, self).__init__(*args, **kwargs)
>          gevent.spawn(self.__thread)
>  
>      def __thread(self):
> -        code.InteractiveConsole().interact("Ryu Debug Console")
> +        code.interact(banner="Ryu Debug Console", readfunc=_raw_input)
>  
>          # XXX should be a graceful shutdown
>          os.kill(os.getpid(), signal.SIGTERM)
> -- 
> 1.7.10.4
> 
> 
> 
> 
> On Mon, Mar 11, 2013 at 02:18:26PM +0900, YAMAMOTO Takashi wrote:
>> 
>> Signed-off-by: YAMAMOTO Takashi <[email protected]>
>> ---
>>  ryu/app/debug_console.py | 37 +++++++++++++++++++++++++++++++++++++
>>  1 file changed, 37 insertions(+)
>>  create mode 100644 ryu/app/debug_console.py
>> 
>> diff --git a/ryu/app/debug_console.py b/ryu/app/debug_console.py
>> new file mode 100644
>> index 0000000..ab9d3a2
>> --- /dev/null
>> +++ b/ryu/app/debug_console.py
>> @@ -0,0 +1,37 @@
>> +# Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
>> +# Copyright (C) 2013 YAMAMOTO Takashi <yamamoto at valinux co jp>
>> +#
>> +# Licensed under the Apache License, Version 2.0 (the "License");
>> +# you may not use this file except in compliance with the License.
>> +# You may obtain a copy of the License at
>> +#
>> +#    http://www.apache.org/licenses/LICENSE-2.0
>> +#
>> +# Unless required by applicable law or agreed to in writing, software
>> +# distributed under the License is distributed on an "AS IS" BASIS,
>> +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
>> +# implied.
>> +# See the License for the specific language governing permissions and
>> +# limitations under the License.
>> +
>> +# a RyuApp to provide a python interactive console for debugging
>> +
>> +import code
>> +import gevent
>> +import os
>> +import sys
>> +import signal
>> +
>> +from ryu.base import app_manager
>> +
>> +
>> +class DebugConsole(app_manager.RyuApp):
>> +    def __init__(self, *args, **kwargs):
>> +        super(DebugConsole, self).__init__(*args, **kwargs)
>> +        gevent.spawn(self.__thread)
>> +
>> +    def __thread(self):
>> +        code.InteractiveConsole().interact("Ryu Debug Console")
>> +
>> +        # XXX should be a graceful shutdown
>> +        os.kill(os.getpid(), signal.SIGTERM)
>> -- 
>> 1.8.0.1
>> 
>> 
>> ------------------------------------------------------------------------------
>> Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
>> Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
>> endpoint security space. For insight on selecting the right partner to 
>> tackle endpoint security challenges, access the full report. 
>> http://p.sf.net/sfu/symantec-dev2dev
>> _______________________________________________
>> Ryu-devel mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>> 
> 
> -- 
> yamahata
> 
> ------------------------------------------------------------------------------
> Minimize network downtime and maximize team effectiveness.
> Reduce network management and security costs.Learn how to hire 
> the most talented Cisco Certified professionals. Visit the 
> Employer Resources Portal
> http://www.cisco.com/web/learning/employer_resources/index.html
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
# Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
# Copyright (C) 2013 YAMAMOTO Takashi <yamamoto at valinux co jp>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# a RyuApp to provide a python interactive console for debugging

import code
import os
import sys
import signal
import eventlet.patcher
threading = eventlet.patcher.original('threading')

from ryu.base import app_manager


class DebugConsole(app_manager.RyuApp):
    def __init__(self, *args, **kwargs):
        super(DebugConsole, self).__init__(*args, **kwargs)
        t = threading.Thread(target=self.__thread)
        t.setDaemon(True)
        t.start()

    def __thread(self):
        code.InteractiveConsole().interact("Ryu Debug Console")

        # XXX should be a graceful shutdown
        os.kill(os.getpid(), signal.SIGTERM)
------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire 
the most talented Cisco Certified professionals. Visit the 
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to