Have anybody tried debugging celeryd worker using pdb? Whenever a breakpoint is encountered (either by running celeryd via pdb, or by pdb.set_trace()), I hit the following error:
Error while handling action event.
Traceback (most recent call last):
File "/home/jeeyo/workspace3/uwcr/subscriptions/tasks.py", line 79, in process_action_event
func(action_event)
File "/home/jeeyo/workspace3/uwcr/subscriptions/tasks.py", line 36, in new_user_email
send_registration_email(username, new_user.get_profile().plaintext_password)
File "/home/jeeyo/workspace3/uwcr/looers/email.py", line 18, in send_registration_email
'Your password from UWCoopRankings', user
File "/home/jeeyo/workspace3/uwcr/looers/email.py", line 61, in send_email
if isinstance(to, basestring):
File "/home/jeeyo/workspace3/uwcr/looers/email.py", line 61, in send_email
if isinstance(to, basestring):
File "/usr/lib/python2.6/bdb.py", line 46, in trace_dispatch
return self.dispatch_line(frame)
File "/usr/lib/python2.6/bdb.py", line 65, in dispatch_line
if self.quitting: raise BdbQuit
BdbQuit
Any solution to this?
I had the same problem. Try using Celery's remote debugger rdb instead:
from celery import task
from celery.contrib import rdb
#task()
def add(x, y):
result = x + y
rdb.set_trace() # <- set break-point
return result
See the user guide (link update 2017/5).
Related
I have deployed Flask Server on IIS. I'm getting below error while importing IPython module in my code.
I have tried IPython version: 5.0, 6.0, 7.16.3 but still
When i run my code through cmd it works and server on localhost starts. But when hosted through IIS Server below issue remains If I keep import IPython line in code.
My python config:
python 3.6
Flask==1.1.2
Keras==2.1.3
scikit-learn==0.23.2
scipy==1.4.1
tensorflow==1.14.0
wfastcgi==3.0.0
Heres my code:
from flask import Flask
import IPython
app = Flask(__name__)
#app.route("/flaskapi2/")
def hello():
return "Hello from FastCGI via IIS!"
if __name__ == "__main__":
app.run()
Error:
Error occurred while reading WSGI handler:
Traceback (most recent call last):
File "E:\deploy_car_damage\wfastcgi.py", line 791, in main
env, handler = read_wsgi_handler(response.physical_path)
File "E:\deploy_car_damage\wfastcgi.py", line 633, in read_wsgi_handler
handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
File "E:\deploy_car_damage\wfastcgi.py", line 600, in get_wsgi_handler
handler = __import__(module_name, fromlist=[name_list[0][0]])
File ".\main.py", line 2, in <module>
import IPython
File "E:\deploy_car_damage\venv36\lib\site-packages\IPython\__init__.py", line 56, in <module>
from .terminal.embed import embed
File "E:\deploy_car_damage\venv36\lib\site-packages\IPython\terminal\embed.py", line 15, in <module>
from IPython.core.interactiveshell import DummyMod, InteractiveShell
File "E:\deploy_car_damage\venv36\lib\site-packages\IPython\core\interactiveshell.py", line 63, in <module>
from IPython.utils import io
File "E:\deploy_car_damage\venv36\lib\site-packages\IPython\utils\io.py", line 94, in <module>
stdin = IOStream(sys.stdin, fallback=devnull)
File "E:\deploy_car_damage\venv36\lib\site-packages\IPython\utils\io.py", line 38, in __init__
for meth in filter(clone, dir(stream)):
File "E:\deploy_car_damage\venv36\lib\site-packages\IPython\utils\io.py", line 37, in clone
return not hasattr(self, meth) and not meth.startswith('_')
File "E:\deploy_car_damage\venv36\lib\site-packages\IPython\utils\io.py", line 81, in closed
return self.stream.closed
ValueError: underlying buffer has been detached
StdOut:
StdErr:
What does underlying buffer has been detached mean and how can I resolve it.
I have written a short python script that uses bleak and asyncio to control a bluetooth LE device. The script works exactly as intended when I run it manually in pycharm or terminal, however I want to run it at specific intervals using crontab.
I've searched for a solution and tried adding absolute paths as well as logging errors. I have found that the script throws an error when run from crontab but I don't quite understand how to fix it.
Here is the script:
#!/usr/bin/python
from bleak import BleakClient
import asyncio
address = "DFB18A2C-6BAB-439E-AF05-485FB4259B75"
MODEL_NBR_UUID = "99FA0002-338A-1024-8A49-009C0215F78A"
async def main(address):
async with BleakClient(address) as client:
for i in range(3):
await client.write_gatt_char(MODEL_NBR_UUID, bytes.fromhex("0800"))
time.sleep(0.5)
asyncio.run(main(address))
And here is the error from crontab log:
Traceback (most recent call last):
File "/Users/emileberhard/PycharmProjects/BedMove/main.py", line 19, in <module>
asyncio.run(main(address))
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/Users/emileberhard/PycharmProjects/BedMove/main.py", line 13, in main
async with BleakClient(address) as client:
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/bleak/backends/client.py", line 61, in __aenter__
await self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/bleak/backends/corebluetooth/client.py", line 78, in connect
device = await BleakScannerCoreBluetooth.find_device_by_address(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/bleak/backends/scanner.py", line 220, in find_device_by_address
return await cls.find_device_by_filter(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/bleak/backends/scanner.py", line 249, in find_device_by_filter
async with cls(detection_callback=apply_filter, **kwargs):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/bleak/backends/corebluetooth/scanner.py", line 44, in __init__
self._manager = CentralManagerDelegate.alloc().init()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/bleak/backends/corebluetooth/CentralManagerDelegate.py", line 88, in init
raise BleakError("Bluetooth device is turned off")
bleak.exc.BleakError: Bluetooth device is turned off
Exception ignored in: <CentralManagerDelegate objective-c instance 0x0>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/bleak/backends/corebluetooth/CentralManagerDelegate.py", line 102, in __del__
IndexError: NSRangeException - Cannot remove an observer <CentralManagerDelegate 0x7fd036fbe0b0> for the key path "isScanning" from <CBCentralManager 0x600000aab100> because it is not registered as an observer.
Exception ignored in: <function CentralManagerDelegate.__del__ at 0x7fd01863cca0>
I'm running MacOS btw!
Thanks in advance!
remove that command from your cronjob.
do this, select your editor of choice from the list.
sudo crontab -e
then add your cronjob, exit and then save (these will run as root)
0 0 * * * /usr/local/bin/python3.9 /users/emileberhard/PycharmProjects/BedMove/main.py >> /users/emileberhard/out2.txt 2>&1
This happens when you have bluetooth off on your OSX device.
I suddenly cannot set any breakpoint in my python program. Note there are two (Pdb) showing up. I wonder if the Pdb was damaged before. I did try to step into some compiled C++ code in an abc.so file using Pdb before this issue started happening:
-> print('haha')
(Pdb) (Pdb)
Traceback (most recent call last):
File "high.py", line 38, in <module>
print('haha')
File "high.py", line 38, in <module>
print('haha')
File "/Users/ludaming/anaconda2/lib/python2.7/bdb.py", line 49, in trace_dispatch
return self.dispatch_line(frame)
File "/Users/ludaming/anaconda2/lib/python2.7/bdb.py", line 68, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
Now I figured it out that the Pdb is not malfunctioning. It is because Python reads from stdin right next to the Pdb, which enters to the Pdb's interactive console and causing a problem. So a bypass is to read from file instead of stdin
fp = open(sys.argv[1], 'r')
t = int(fp.readline())
instead of
t = int(raw_input())
I am calling an R script file from python using pyrserve. I have rserve running. At arbitrary points in the R script, pyrserve gives an error and quits:
Traceback (most recent call last):
File "scriptV2.py", line 272, in <module>
rConn.eval("source(file.PropensityFlow)")
File "/Users/dipayanmaiti/Py3.3venv/lib/python3.3/site-packages/pyRserve/rconn.py", line 47, in decoCheckIfClosed
return func(self, *args, **kw)
File "/Users/dipayanmaiti/Py3.3venv/lib/python3.3/site-packages/pyRserve/rconn.py", line 119, in eval
return rparse(src, atomicArray=atomicArray)
File "/Users/dipayanmaiti/Py3.3venv/lib/python3.3/site-packages/pyRserve/rparser.py", line 539, in rparse
return rparser.parse()
File "/Users/dipayanmaiti/Py3.3venv/lib/python3.3/site-packages/pyRserve/rparser.py", line 349, in parse
self.lexer.readHeader()
File "/Users/dipayanmaiti/Py3.3venv/lib/python3.3/site-packages/pyRserve/rparser.py", line 94, in readHeader
self.responseCode = struct.unpack(b'<i', self.read(3) + b'\x00')[0]
File "/Users/dipayanmaiti/Py3.3venv/lib/python3.3/site-packages/pyRserve/rparser.py", line 149, in read
raise EndOfDataError()
pyRserve.rparser.EndOfDataError
I have set rserv.conf to the following:
maxinbuf 20000000
maxsendbuf 0
Does anybody know why this happens? This looks like some buffer problem, because the R script runs by itself.
It is a late answer, but in such situations it is useful to run Rserve in debug mode so its output can be monitored in a separate shell.
R CMD Rserve.dbg
In some rare cases I've seen Rserve printing warnings to the console, and when this happened the command sent thru pyRserve didn't return any value from Rserve - which led to the 'EndOfDataError' above.
I'm relatively new to python and pdb, but I have a lot of experience with gdb.
My problem is that if I set a number of breakpoints in my code at some point I will want to change something and re-run my debug session retaining these break points. However entering "run" in my pdb session cases my session to terminate with the following output
(Pdb) run
Traceback (most recent call last):
File "/usr/lib64/python2.6/runpy.py", line 122, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib64/python2.6/runpy.py", line 34, in _run_code
exec code in run_globals
File "/usr/lib64/python2.6/pdb.py", line 1319, in <module>
pdb.main()
File "/usr/lib64/python2.6/pdb.py", line 1312, in main
pdb.interaction(None, t)
File "/usr/lib64/python2.6/pdb.py", line 198, in interaction
self.cmdloop()
File "/usr/lib64/python2.6/cmd.py", line 142, in cmdloop
stop = self.onecmd(line)
File "/usr/lib64/python2.6/pdb.py", line 267, in onecmd
return cmd.Cmd.onecmd(self, line)
File "/usr/lib64/python2.6/cmd.py", line 219, in onecmd
return func(arg)
File "/usr/lib64/python2.6/pdb.py", line 661, in do_run
raise Restart
pdb.Restart
]$
I've tried this on two independent linux platforms and had the same result but I cannot find any corrections in the documentation.
So if anyone cares the problem was that "run" in pdb is not the exact same as "run" in gdb. In gdb if I enter run the program restarts and continues to the first break point. In pdb the program restarts and goes to the start of the file. I then have to press 'n' followed by 'c' to get to the first break point. If, attempting to get the program to run, I type run a second time at the start of the file the debugger crashes, as shown above.
Here is my file test.py:
import pdb
pdb.set_trace()
print('1 line')
I get the same error when I using command 'python3 test.py':
> /home/wangpq/program_note/test.py(3)<module>()
-> print('1 line')
(Pdb) run
Traceback (most recent call last):
File "program_note/test.py", line 3, in <module>
print('1 line')
File "program_note/test.py", line 3, in <module>
print('1 line')
File "/usr/lib/python3.5/bdb.py", line 48, in trace_dispatch
return self.dispatch_line(frame)
File "/usr/lib/python3.5/bdb.py", line 66, in dispatch_line
self.user_line(frame)
File "/usr/lib/python3.5/pdb.py", line 259, in user_line
self.interaction(frame, None)
File "/usr/lib/python3.5/pdb.py", line 346, in interaction
self._cmdloop()
File "/usr/lib/python3.5/pdb.py", line 319, in _cmdloop
self.cmdloop()
File "/usr/lib/python3.5/cmd.py", line 138, in cmdloop
stop = self.onecmd(line)
File "/usr/lib/python3.5/pdb.py", line 412, in onecmd
return cmd.Cmd.onecmd(self, line)
File "/usr/lib/python3.5/cmd.py", line 217, in onecmd
return func(arg)
File "/usr/lib/python3.5/pdb.py", line 1022, in do_run
raise Restart
pdb.Restart
Then I use command 'python3 -m pdb test.py'
wangpq#wangpq:~$ python3 -m pdb program_note/test.py
> /home/wangpq/program_note/test.py(1)<module>()
-> import pdb
(Pdb) restart
Restarting program_note/test.py with arguments:
program_note/test.py
> /home/wangpq/program_note/test.py(1)<module>()
-> import pdb
(Pdb)
It works. So far, I am not sure why this happens.
Upon encountering an abnormal condition (i.e., a bug in your program), pdb rather helpfully says:
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
Here, typing "run" or "restart" will cause the pdb process to unceremoniously terminate as OP states (but "cont" or "step" will restart as promised).
Presumably many impatient pythonistas would rather "run" or "restart" work regardless of whether we've entered "post mortem debugging" but I'm sure the existing restart semantics is the byproduct of a cleaner implementation.