相关疑难解决方法(0)

Django Rest Framework调试发布和放置请求

我使用DRF扩展来获取模型的se json列表,并且我可以使用debug-toolbarGET请求进行调试,但是我如何调试POSTPUT请求?

我有这个用于调试模式的设置:

INSTALLED_APPS += ('debug_toolbar',)

MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)

DEBUG_TOOLBAR_PATCH_SETTINGS = False
INTERNAL_IPS = (
    '127.0.0.1'
)
Run Code Online (Sandbox Code Playgroud)

现在,当我Intercept redirects在调试工具栏中尝试时,它不会显示我的工具栏POST.

django django-debug-toolbar django-rest-framework

10
推荐指数
3
解决办法
9634
查看次数

并发.futures.ThreadPoolExecutor不打印错误

我正在尝试使用并发.futures.ThreadPoolExecutor 模块并行运行类方法,我的代码的简化版本几乎如下:

class TestClass:

    def __init__(self, secondsToSleepFor):

        self.secondsToSleepFor = secondsToSleepFor


    def testMethodToExecInParallel(self):

        print("ThreadName: " + threading.currentThread().getName())
    

        print(threading.currentThread().getName() + " is sleeping for " + str(self.secondsToSleepFor) + " seconds")
    

        time.sleep(self.secondsToSleepFor)


        print(threading.currentThread().getName() + " has finished!!")


with concurrent.futures.ThreadPoolExecutor(max_workers = 2) as executor:

    futuresList = []

    print("before try")

    try:

         testClass = TestClass(3)        

         future = executor.submit(testClass.testMethodToExecInParallel)

         futuresList.append(future)

    except Exception as exc:

         print('Exception generated: %s' % exc)
Run Code Online (Sandbox Code Playgroud)

如果我执行这段代码,它的行为似乎就像它预期的那样。但是,如果我犯了一个错误,例如在“testMethodToExecInParallel”中指定了错误数量的参数,例如:

 def testMethodToExecInParallel(self, secondsToSleepFor):
Run Code Online (Sandbox Code Playgroud)

然后仍然将函数提交为:

future = executor.submit(testClass.testMethodToExecInParallel)
Run Code Online (Sandbox Code Playgroud)

或者尝试在“testMethodToExecInParallel”方法中的打印语句内将字符串对象与整数对象连接(不使用 str(.) ):

def testMethodToExecInParallel(self):

        print("ThreadName: " + threading.currentThread().getName())
        print("self.secondsToSleepFor: …
Run Code Online (Sandbox Code Playgroud)

python multithreading python-3.x concurrent.futures

6
推荐指数
1
解决办法
8273
查看次数