You can always run Django in single threaded mode
python manage.py runserver--nothreading
You can always run Django in single anycodings_sqlite threaded mode,Is there a way to migitate this issue with anycodings_ipdb ipdb and make it more multi-thread / anycodings_ipdb autoreload safe?,After this, either the program cannot be anycodings_ipdb closed (hanging threads) or ipdb itself anycodings_ipdb stops working.,I am using ipdb debugger to debug anycodings_ipdb multithreaded web applications locally anycodings_ipdb (Django, Plone). Often ipdb seems to get anycodings_ipdb confused because of the autoreload which anycodings_ipdb happens when I am on the debug prompt. The anycodings_ipdb resulting stack trace comes up
I am using ipdb debugger to debug anycodings_ipdb multithreaded web applications locally anycodings_ipdb (Django, Plone). Often ipdb seems to get anycodings_ipdb confused because of the autoreload which anycodings_ipdb happens when I am on the debug prompt. The anycodings_ipdb resulting stack trace comes up
/Users/mikko / code / xxxx / venv / lib / python2 .7 / site - packages / IPython / core / history.pyc in writeout_cache(self, conn)
605 with self.db_input_cache_lock:
606
try:
-- > 607 self._writeout_input_cache(conn)
608 except sqlite3.IntegrityError:
609 self.new_session(conn)
/
Users / mikko / code / xxxx / venv / lib / python2 .7 / site - packages / IPython / core / history.pyc in _writeout_input_cache(self, conn)
589
for line in self.db_input_cache:
590 conn.execute("INSERT INTO history VALUES (?, ?, ?, ?)",
-- > 591(self.session_number, ) + line)
592
593 def _writeout_output_cache(self, conn):
ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 4546363392 and this is thread id 140735211872640
You can always run Django in single anycodings_sqlite threaded mode
python manage.py runserver--nothreading
You can launch a Python program through pdb by using pdb myscript.py or python -m pdb myscript.py.,ipdb, multiple threads and autoreloading programs causing ProgrammingError,multithreading does not work well if you don't hack some settings... ipdb, multiple threads and autoreloading programs causing ProgrammingError https://github.com/gotcha/ipdb/issues/51 ,you would have to go through all function and class definitions as Python reads those lines
Most straight forward way, running from command line, of python interpreter
$ python -m pdb scriptName.py > .../pdb_script.py(7)<module>() -> """ (Pdb)
While developing early versions of modules and to experiment it more iteratively.
$ python Python 2.7 (r27:82508, Jul 3 2010, 21:12:11) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import pdb_script >>> import pdb >>> pdb.run('pdb_script.MyObj(5).go()') > <string>(1)<module>() (Pdb)
For a big project and long-running module, can start the debugging from inside the program using import pdb and set_trace() like this :
#!/usr/bin/env python # encoding: utf-8 # import pdb class MyObj(object): count = 5 def __init__(self): self.count= 9 def go(self): for i in range(self.count): pdb.set_trace() print i return if __name__ == '__main__': MyObj(5).go()
There is a module called 'pdb' in python. At the top of your python script you do
import pdb pdb.set_trace()
Starting in Python 3.7, you can use the breakpoint()
built-in function to enter the debugger:
foo() breakpoint() # drop into the debugger at this point bar()
Usage is analogous to pdb
, just install it with:
python3 - m pip install--user ipdb
and then add to the line you want to step debug from:
__import__('ipdb').set_trace(context = 21)
You likely want to add a shortcut for that from your editor, e.g. for Vim snipmate I have:
snippet ipd __import__('ipdb').set_trace(context = 21)
Or alternatively, as in raw pdb 3.2+ you can set some breakpoints from the command line:
ipdb3 - c 'b 12' - c 'b myfunc'~/test/a.py
python -m module
debugging has been asked at: How to debug a Python module run with python -m from the command line? and since Python 3.7 can be done with:
python - m pdb - m my_module
You can launch a Python program through pdb by using pdb myscript.py or python -m pdb myscript.py.,ipdb, multiple threads and autoreloading programs causing ProgrammingError,multithreading does not work well if you don't hack some settings...ipdb, multiple threads and autoreloading programs causing ProgrammingErrorhttps://github.com/gotcha/ipdb/issues/51,you would have to go through all function and class definitions as Python reads those lines
Most straight forward way, running from command line, of python interpreter
$ python -m pdb scriptName.py
> .../pdb_script.py(7)<module>()
-> """
(Pdb)
While developing early versions of modules and to experiment it more iteratively.
$ python
Python 2.7 (r27:82508, Jul 3 2010, 21:12:11)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pdb_script
>>> import pdb
>>> pdb.run('pdb_script.MyObj(5).go()')
> <string>(1)<module>()
(Pdb)
For a big project and long-running module, can start the debugging from inside the program using import pdb and set_trace()like this :
#!/usr/bin/env python
# encoding: utf - 8
#
import pdb
class MyObj(object): count = 5 def __init__(self): self.count = 9 def go(self): for i in range(self.count): pdb.set_trace() print i
return
if __name__ == '__main__': MyObj(5).go()
Starting in Python 3.7, you can use the breakpoint()
built-in function to enter the debugger:
foo() breakpoint() # drop into the debugger at this point bar()
Usage is analogous to pdb
, just install it with:
python3 - m pip install--user ipdb
The IP address used in listen should be the remote computer's private IP address. You can then launch the program normally, causing it to pause until the debugger attaches.,In your Python code, you can call debugpy.breakpoint() at any point where you want to pause the debugger during a debugging session.,In your VS Code workspace, create a configuration for remote debugging in your launch.json file, setting the port to match the port used in the ssh command and the host to localhost. You use localhost here because you've set up the SSH tunnel.,You would then use the following configuration to attach from the VS Code Python extension.
In the script code, add the following and save the file:
import debugpy # 5678 is the default attach port in the VS Code debug configurations.Unless a host and port are specified, host defaults to 127.0 .0 .1 debugpy.listen(5678) print("Waiting for debugger attach") debugpy.wait_for_client() debugpy.breakpoint() print('break on this line')
Enable port forwarding by opening the sshd_config
config file (found under /etc/ssh/
on Linux and under %programfiles(x86)%/openssh/etc
on Windows) and adding or modifying the following setting:
AllowTcpForwarding yes
In your VS Code workspace, create a configuration for remote debugging in your launch.json
file, setting the port to match the port used in the ssh
command and the host to localhost
. You use localhost
here because you've set up the SSH tunnel.
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost",
"pathMappings": [{
"localRoot": "${workspaceFolder}", // Maps C:\Users\user1\project1
"remoteRoot": "." // To current working directory ~/project1
}]
}
In the source code, add the following lines, replacing address
with the remote computer's IP address and port number (IP address 1.2.3.4 is shown here for illustration only).
import debugpy # Allow other computers to attach to debugpy at this IP address and port. debugpy.listen(('1.2.3.4', 5678)) # Pause the program until a remote debugger is attached debugpy.wait_for_client()
Launch the remote process through debugpy, for example:
python3 - m debugpy--listen 1.2 .3 .4: 5678--wait -
for -client - m myproject
Local computer: Only if you modified the source code on the remote computer as outlined above, then in the source code, add a commented-out copy of the same code added on the remote computer. Adding these lines makes sure that the source code on both computers matches line by line.
#import debugpy # Allow other computers to attach to debugpy at this IP address and port. #debugpy.listen(('1.2.3.4', 5678)) # Pause the program until a remote debugger is attached #debugpy.wait_for_client()
04/22/2022
Thread 1
Total = Total + val1
Thread 2
Total = Total - val2
Thread 1
1. mov eax, dword ptr ds: [031 B49DCh] 2. add eax, edi 3. jno 00000033 4. xor ecx, ecx 5. call 7611097 F 6. mov dword ptr ds: [031 B49DCh], eax
Thread 2
1. mov eax, dword ptr ds: [031 B49DCh] 2. sub eax, edi 3. jno 00000033 4. xor ecx, ecx 5. call 76110 BE7 6. mov dword ptr ds: [031 B49DCh], eax
Thread 1
SyncLock LeftVal SyncLock RightVal 'Perform operations on LeftVal and RightVal that require read and write. End SyncLock End SyncLock
Thread 2
SyncLock RightVal SyncLock LeftVal 'Perform operations on RightVal and LeftVal that require read and write. End SyncLock End SyncLock